I am reading an REST API in JSON format. When reading the JSON i cannot extract the leaves with JSONPath. So what i would like to do is run thru the JSON string with Java and get the values i need, they are always in the same order. This is the JSON string i need to extract values from:
{
"10516": {
"estimated": {
"value": 10.0,
"text": "10.0"
},
"completed": {
"value": 7.5,
"text": "7.5"
}
},
"10244": {
"estimated": {
"value": 15.5,
"text": "15.5"
},
"completed": {
"value": 7.5,
"text": "7.5"
}
},
"10182": {
"estimated": {
"value": 12.0,
"text": "12.0"
},
"completed": {
"value": 10.0,
"text": "10.0"
}
},
"10391": {
"estimated": {
"value": 16.0,
"text": "16.0"
},
"completed": {
"value": 3.0,
"text": "3.0"
}
},
"10183": {
"estimated": {
"value": 12.0,
"text": "12.0"
},
"completed": {
"value": 7.0,
"text": "7.0"
}
},
"10123": {
"estimated": {
"value": 11.5,
"text": "11.5"
},
"completed": {
"value": 5.5,
"text": "5.5"
}
},
"10447": {
"estimated": {
"value": 7.0,
"text": "7.0"
},
"completed": {
"value": 3.0,
"text": "3.0"
}
}}
As you can see the ID 10516
has estimated
and completed
, i would like to extract those values for each ID. So the output should look like this:
ID | ESTIMATED | COMPLETED
10516 | 10.0 | 7.5
10244 | 15.5 | 7.5
10182 | 12.0 | 10.0
and so on..
it is important that for every ID the values are in the same row because i need to upload them to my PostgreSQL db and join this data with other data on the ID.
My idea is to coun't the values surrounded by quotation marks and get the 1st, 5th, 9th, 10th, 14th and 18th value and so on. because the JSON string is always in the same order i guess it could be done like that..
please help out and keep in mind i don't have any experience in java at all and the implementation will be done in Talend Open Studio. also see my other question that raised this question because JSONPath cannot help me: Extract leaves from JSON file with JSONpath