cancel
Showing results for 
Search instead for 
Did you mean: 

Reading dynamic json format

ChinuBansal
Level 2
Hi All,

I am using dot notation to extract JSON response property as mentioned below:

17869.png
But the challenge here is id i.e. 123 is dynamic and when I am dynamically passing variable its not accepting it and throwing below error:

17870.png

Can anybody help please ?

Regards,
Chinu




------------------------------
Chinu Bansal
Developer
Zensar
Europe/London
------------------------------
4 REPLIES 4

TusharVarshney
Level 5
/@ChinuBansal - you could use  extract the value till JSON:Array in temp collection followed by Get collection field Action. add a logic to identify the field name as per requirement.​
#coinchallenge
------------------------------
Tushar Varshney
Senior Consultant - Intelligent Automation
Ernst & Young India
+91-9880188366
------------------------------
Tushar Varshney Senior Consultant - Intelligent Automation Ernst & Young India +91-9880188366

david.l.morris
Level 15
I'd agree with Tushar's suggestion. Use a calculation stage to extract the collection up to the dynamic number, such as [col_JSON_Data.data.results.JSON:Array] and store that into a new different collection. Then you can loop through that new collection if needed and you can get data out of the fields by using the object 'Utility - Collection Manipulation' with the action 'Read Collection Field' which lets you dynamically specify the Field Name.

Edit: Reading your post again, it occurs to me that part of the issue is that it looks like you're actually trying to get a collection instead of a specific value even at the bottom of the hierarchy of nested collections. I'd say just use Calculation stages in order to extract nested collections, and that should get you what you need even if it feels a bit clunky.

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

SandeepNalla
Level 3
Were you able to figure out this out? I'm facing the same issue.

------------------------------
Sandeep Nalla
Senior Consultant
Lateetud Inc
America/New_York
------------------------------

Ok, so to be honest the built in methods for interacting with JSON in BP are lacking. As you can see it does not handle dynamic JSON well and there is actually a few other problems (eg. JSON with Property Names that have periods in them) These will actually be put in Collection Field Headers so that you end up with a Collection Field Header named something like 'Email.Id' which if you then try to use dot notation with.... well, you'll have a nice headache. I'd strong recommended using a library like JSON.NET or Newtonsoft and building custom code stages for advanced JSON actions. For instance, you might want to build an action that checks if a JSON Property exists ^ would solve your problem, or to extract a specific value at a specific property, these are all easily doable with Newtonsoft and some C# or VB.NET. A lot of APIs that return JSON will return it dynamically simply to conserve processing power server side so in the long run this is the more scalable approach to things. If however this is truly a one off for you you're probably best doing some manipulation with collections and strings like people discussed above.

------------------------------
Erin Connerley
Automation Consultant
Agilify Automation
America/Indiana/Indianapolis
------------------------------