Found empty property error using json.path.read

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
notbono
Cave Troll
Posts: 61
Joined: Sun Oct 24, 2010 4:44 pm

Found empty property error using json.path.read

Post by notbono »

Note that I'm using 1.7.0

Code: Select all

[h: Location = "Backpack1"]
[h: ItemKey = "Blanket, woollen"]

[h: jGearList = '{"OnPerson":{"Contents":{"Backpack1":{"Type":"Backpack","Weight":"10","Cost":"2gp","Capacity":"50","Contents":{"Blanket, woollen": "Yes"},"ContentWeight":0},"Backpack2":{"Type":"Backpack","Weight":"10","Cost":"2gp","Capacity":"50","Contents":{},"ContentWeight":0},"Backpack3":{"Type":"Backpack","Weight":"10","Cost":"2gp","Capacity":"50","Contents":{},"ContentWeight":0}},"ContentWeight":0},"NotOnPerson":{"Contents":{},"ContentWeight":0}}']
[h: xExpression =  "\$..['" + Location + "']['Contents']['" + ItemKey + "']"]
[r: xExpression]
[jItemArray = json.path.read(jGearList, xExpression) ]
[r: jItemArray ]
This snippet should replicate the issue I'm having. It seems to be a problem with my expression rather than my json, since the message changes based on the length of the ItemKey variable.

I get 'Error with function "json.path.read": Found empty property at index 47'

The expression and json work okay at this json path expression tester: https://jsonpath.curiousconcept.com/

To run it there, you can paste this json:

Code: Select all

{"OnPerson":{"Contents":{"Backpack1":{"Type":"Backpack","Weight":"10","Cost":"2gp","Capacity":"50","Contents":{"Blanket, woollen": "Yes"},"ContentWeight":0},"Backpack2":{"Type":"Backpack","Weight":"10","Cost":"2gp","Capacity":"50","Contents":{},"ContentWeight":0},"Backpack3":{"Type":"Backpack","Weight":"10","Cost":"2gp","Capacity":"50","Contents":{},"ContentWeight":0}},"ContentWeight":0},"NotOnPerson":{"Contents":{},"ContentWeight":0}}
and this expression:

Code: Select all

$..['Backpack1']['Contents']['Blanket, woollen']

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Found empty property error using json.path.read

Post by aliasmask »

I would try and remove the \$ and see if it works. There's also a couple of config options that can be set to fine tune the return value result.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Found empty property error using json.path.read

Post by wolph42 »

aliasmask wrote:
Sun Aug 02, 2020 10:13 am
I would try and remove the \$ and see if it works. There's also a couple of config options that can be set to fine tune the return value result.
...or add another escape \\$ which might also work.

notbono
Cave Troll
Posts: 61
Joined: Sun Oct 24, 2010 4:44 pm

Re: Found empty property error using json.path.read

Post by notbono »

When I take it out I get: Error with function "json.path.read": Character '.' on position 3 is not valid.


When I add a second escape character: java.lang.IllegalArgumentException: Illegal group reference error executing expression xExpression = "\\$..['" + Location + "']['Contents']['" + ItemKey + "']".

I did experiment with the config options, particularly the "ignore exceptions" one, but it didn't make any difference.

notbono
Cave Troll
Posts: 61
Joined: Sun Oct 24, 2010 4:44 pm

Re: Found empty property error using json.path.read

Post by notbono »

It appears that the comma in the key is causing the problem. So I guess I'm going to need a work around for that, since my equipment list is full of commas like that.

notbono
Cave Troll
Posts: 61
Joined: Sun Oct 24, 2010 4:44 pm

Re: Found empty property error using json.path.read

Post by notbono »

The workaround consists of double-escaping the comma in the key, but not escaping the comma in the json.

[h: ItemKey = "Blanket\\, woollen"]

I wouldn't have thought to try a double escape here, thanks for that idea wolph42.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Found empty property error using json.path.read

Post by aliasmask »

Yeah, that's a weird one. Seems like a bug to me.

notbono
Cave Troll
Posts: 61
Joined: Sun Oct 24, 2010 4:44 pm

Re: Found empty property error using json.path.read

Post by notbono »

I have no idea how to report a bug, but yes this does seem like one. Requiring an escape for the comma appears to be a bug in the JayWay implementation of json path, which is what maptool uses I think. https://github.com/json-path/JsonPath/issues/400

The double escape requirement is probably a bug of the maptool parser.

Post Reply

Return to “Macros”