wanglingsong / JsonSurfer

A streaming JsonPath processor in Java
MIT License
294 stars 55 forks source link

Keys containin a space cannot be parsed #47

Closed amanzan closed 5 years ago

amanzan commented 5 years ago

I have a json with some keys that contain spaces ("Image Player". "Phone Number"). There's a ParseCancellationException if I try to parse it:

MyApp.getJsonSurfer().collectOne(jsonAsString, "$.fields.Phone Number")

How to handle when keys have spaces?

Here's the sample json:

{ "id": "some_id", "fields": { "Email": "email@example.com", "Status": "Amateur", "Image player": [ { "id": "some_other_id", "url": "https://www.google.es", "filename": "image.png", "size": 413642, "type": "image/png", "thumbnails": { "small": { "width": 36, "height": 36 }, "large": { "width": 500, "height": 500 }, "full": { "width": 500, "height": 500 } } } ], "Phone Number": "666666666", "Name": "Player one", "Wins": [ 0 ], "Standing": [ "Eliminated" ] }, "createdTime": "2018-06-28T22:32:47.000Z" }

wanglingsong commented 5 years ago

Try this: $.fields['Phone Number']

amanzan commented 5 years ago

That didn't work either, but after several tests, apparently this works:

MyApp.getJsonSurfer().collectOne(jsonAsString, "$.fields[\'Phone Number\']")

With the double quote I was still getting the ParseCancellationException. It would be better if the "." remains between "fields" and the start bracket, but I will try to make it work like this.

Thanks for the quick response!!