first of all you should know that there is no activity to deserialize any json structure and store it in excel or any data table, but you should deserialize then configure your workflow to get specific fields of json you need.
anyway, you should use deserialize JSON activity instead of deserializeJSON Array activity.
you should know something regarding json:
each block in json have postion start from 0
each field in json have nested fields we should put name of header.name of sub name to get it
for elaboration to help you get any filed you want from your json see below
use deserialize json activity and the result store in variable called: âjobjâ
examples:
convert.ToString(jobj.SelectToken(âvalue[0].titleâ)) ==== Test 1
Thank you for the reply, help me understand then how should I get the all date in a DT?
If I proceed as you suggested -
1st I will create all the required header under BuildDT
then read the JSON with Read text file
Then pass the output of above as input for Deserilalize Json
Then pass the output of above to For Each
with in loop assign all the headers items and then store it in Add data row
then pass the output to write range outside the loop to write the data
as you see in json custom field have and each {} inside that block have value start from 0
if you want second template property in custom field you should put convert.ToString(jrr.SelectToken(âvalue[0].customFields[1].templatePropertiesâ))
@takyysh
I appreciate your suggestion but when you state to use [0] that is the index of the json right so how can I get data from 3rd or 4th index? I have to mention the index for every time right? but that will not work, as the json data is dynamic so I can expect 1 data or 1000 data, I canât keep assigning I have to loop it through to get all the data, whatever it has.
Your âvalueâ token contains a Jarray essentially.
Within that Jarray, you have n number of items
Within the 1st item you have your required keys
Some keys like uniqueName can only be obtained by parsing into another jObject âownerâ for example.
And the above pattern continues into your entire Jarray (n number of items)
Use your Excel sample file and clone that table such that you get only the headers with no rows. This datatable is your output datatable to which you will add rows with values.
In your For each item (jobject) in value (jarray) you will have to handle the 1st degree tokens and some can result in a jarray (âcommoditiesâ:) some can be jobject (âownerâ:{})
Each of these needs to be handled induvidually and the values you get can later be set in your output datatable.
I donât get it, even If I take one object at a time then I am putting âValue[0]â right but I have to consider the n object as well, right then I have to make it dynamic then how can I make this âValue[n]â coz the json will always have value more than one.
Can you please suggest ne how can I extract only these below mention header data ? title | owner.name | contractId | customFields.templateProperties
for the first 3 I can be able to extract and able to create DT for the last one I canât able to find a solution yet?
I am processing the same way, like @ppr has suggestion on the topic but at one point I am stuck now that is getting data from templateProperties[] under customFields property, as this filed have no key value, but only value.
You can modify in your for each that if the key is templateProperties then do not use .value but get the fitem(âfieldidâ).ToString, I have not tested this, but It should return
âMasterDataField,ERPIntegrationField,ZoneLeftField,DetailsViewField,EditViewField,CreateViewFieldâ
if it does not, may be you will have to handle the fitem within another for loop to get into the templateProperties. So that in each loop you fetch index values of templateProperties.
yes if you loop that is a better way but i think you should also make some configuration,
to make it dynamically i dont think if there is any activity for json instead of deserialize json or deserialize json array
suggestion to use it from excel there is a way on excel to retrieve data from external resource, and you can get data as json and excel will convert it automatically to data table and store in excel, search for that subject
Also, one more concern arises, i.e, If I have multiple records under the templateProperties tag my rest of the extracted record will print other data that no. of time of templateProperties like below
@takyysh
I am not looking for any particular activity but to make my code with bits and pieces and make it workable.
I am trying the way Peter has suggested but made some changes as per your input as well to make it workable, but I am stuck with the templateProperties tag which is a sub property of customFields tag and it contains array[]