using tExtractJsonFields to extract JSON response from tRestClient
Hi,
I am trying to tExtractJsonFields to parse the JSON response. But JSON response has dynamic keys. How to parse this kind of JSON using tExtractJSONfields. I am using community edition of data integrator 5.5.
Following is an example
{
"apple:ios": {
"2015-10-20": {
"downloads": 72,
"updates": 27,
"returns": 0,
"net_downloads": 72,
"promos": 0,
"revenue": "0.00",
"edu_downloads": 0,
"gifts": 0,
"gift_redemptions": 0,
"storefront": "apple:ios",
"store": "apple",
"date": "2015-10-20"
}
},
"google_play": {
"2015-10-20": {
"downloads": 68,
"updates": 14,
"returns": 0,
"net_downloads": 68,
"promos": 0,
"revenue": "0.00",
"edu_downloads": 0,
"gifts": 0,
"gift_redemptions": 0,
"storefront": "google_play",
"store": "google_play",
"date": "2015-10-20"
}
}
}
Hi
Check the response string to see which key it contains, and use the corresponding tExtractJsonFields to parse the string. Eg:
.....tJavaRow--runIf1---tFixedFlowInput1--main--tExtractJsonFields1
--runIf2---tFixedFlowInput2--main---tExtractJsonFields2
...
on tJavaRow:
if(input_row.response.contains("
apple:ios")){
globalMap.put("is
apple:ios",true);
}else{
globalMap.put("is
apple:ios",false);
}
set the condition of runif1 as:
(Boolean)globalMap.get("is
apple:ios
")
tExtractJsonFields1: configure to extract the values from the json string whose key is
apple:ios.
This solution is only apply to the situation the number of keys is limited, and the key can be one of the values which is listed on tJavaRow.