JSON question

Hello - I am trying to capture the BikeParking attribute from the Yelp dataset using the json path node and I am unable to do so. I defined it as follows in the JSON path:

$.attributes..BikeParking.

how should I change it?

Please help. I am very much a newbie…

Thank you.

{
“business_id” : “0DI8Dt2PJp07XkVvIElIcQ”,
“name” : “Innovative Vapors”,
“neighborhood” : “”,
“address” : “227 E Baseline Rd, Ste J2”,
“city” : “Tempe”,
“state” : “AZ”,
“postal_code” : “85283”,
“latitude” : 33.3782141,
“longitude” : -111.936102,
“stars” : 4.5,
“review_count” : 17,
“is_open” : 0,
“attributes” : [ “BikeParking: True”, “BusinessAcceptsBitcoin: False”, “BusinessAcceptsCreditCards: True”, “BusinessParking: {‘garage’: False, ‘street’: False, ‘validated’: False, ‘lot’: True, ‘valet’: False}”, “DogsAllowed: False”, “RestaurantsPriceRange2: 2”, “WheelchairAccessible: True” ],
“categories” : [ “Tobacco Shops”, “Nightlife”, “Vape Shops”, “Shopping” ], “hours” : [ “Monday 11:0-21:0”, “Tuesday 11:0-21:0”, “Wednesday 11:0-21:0”, “Thursday 11:0-21:0”, “Friday 11:0-22:0”, “Saturday 10:0-22:0”, “Sunday 11:0-18:0” ], “type” : “business” }

Counterintuitively, attributes is not an object, but an array of key-value strings, which makes it a little difficult to handle.

In case the arrays in each element you want to process have the same size and order, you can go for something like the following and query by index:

$.attributes[0]

Which will give you the entire string "BikeParking: True".

In the other case (array sizes/structure for each item in the dataset differ), I’d suggest to first extract the attributes array into a list column and then extract the flags using additional node logic.

1 Like

In your case, to find a specific element in an array, you can also use a regular expression, to find elements starting with “BikeParking”:

$.attributes[?(@ =~ /^BikeParking:.*/)]
1 Like

Many thanks. Perfect. Picked up the BikeParking.

Many thanks. works, but this picks up only the first element…but thanks again.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.