spark85 / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

keys with "." #45

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Create a doc e.g. like this {"rootkey":{"sub.key":"value"}} and try to select 
the value

with a path like "rootkey.sub.key" you will get a "PathNotFoundException" 
stating that there is no key named sub.

Is it possible to express the path in some other way to get the value?

I'm on jsonpath 0.9.0!

/Jesper

Original issue reported on code.google.com by jeppe.bl...@gmail.com on 20 Feb 2014 at 2:38

GoogleCodeExporter commented 9 years ago
never mind, found a solution...
you can do this rootkey.[sub.key]

/Jesper

Original comment by jeppe.bl...@gmail.com on 20 Feb 2014 at 2:56

GoogleCodeExporter commented 9 years ago
You must use bracket notation to target this property:

        String json = "{\"rootkey\":{\"sub.key\":\"value\"}}";

        assertThat(JsonPath.read(json, "rootkey['sub.key']")).isEqualTo("value");

Original comment by kalle.st...@gmail.com on 4 Aug 2014 at 10:20