Re: JSON nested elements names contain periods. Need to extract data from these elements, JSONPath is struggling with formatting.

53 views
Skip to first unread message
Message has been deleted

Alex Cook

unread,
Aug 3, 2016, 4:03:00 PM8/3/16
to JsonPath


On Wednesday, August 3, 2016 at 1:01:10 PM UTC-7, Alex Cook wrote:
Hello, I have JSON structured like this.

[ { id: { type: [Object], value: '100479' },
    'data.name':
     { type: [Object],
       format: [Object],
       value: 'Alex Cook Jr.' },
    'data.phone': { type: [Object], value: '(xxx) xxx-xxxx' },
    'data.address': { type: [Object], value: [Object] },
    org: { type: [Object], value: false } } ]

I'm processing thousands of these JSON blocks. I want to know whether or not the 'value' of entries 'data.phone' and 'data.address' are null.
They are required to be labeled 'data.phone', 'data.address', due to other processes in the application.

Let me give a few examples of how I am using JSONPath.

var path = "$.item.*~"
var result = JSONPath({json: obj, path: path})

[ 'id', 'data.name', 'data.phone', 'data.address', 'org' ]

//

var path = "$.item.id"
var result = JSONPath({json: obj, path: path})

[ { type: [ 'id' ], value: '100479' } ]

//

var path = "$.item.id.value"
var result = JSONPath({json:obj, path:path})

[ '100479' ]

Now, the problem should be obvious.

var path = var path = "$.item.data.address"
var result = JSONPath({json:obj, path:path})

[]

I think array formatting would work here, but I'm struggling to get array formatting to work the way I want it to.

Any thoughts?

Thanks, JSONPath is very useful.

Alex

EDIT: Just realized the topic 'escaping' might work here.

Reply all
Reply to author
Forward
0 new messages