To expand on Andreas's response, he is correct that your JSON example is malformed in that it has two properties with the same name. Your choice is either to place the G_1 objects in an array like the following:
{
"DATA_DS": {
"P_END_DATE": "2023-11-30T00:00:00.000+00:00",
"G_1": [
{
"VALIDATION_STATUS": "APPROVED",
"INVOICE_NUMBER": "INV_PO.060.60",
"INVOICE_LINENUMBER": "1"
},
{
"VALIDATION_STATUS": "APPROVED",
"INVOICE_NUMBER": "INV_PO.060.60",
"INVOICE_LINENUMBER": "2"
}
]
}
}
Or you can uniquely name the G_1 objects, such as G_1, G_2, G_3 etc.
{
"DATA_DS": {
"P_END_DATE": "2023-11-30T00:00:00.000+00:00",
"G_1": {
"VALIDATION_STATUS": "APPROVED",
"INVOICE_NUMBER": "INV_PO.060.60",
"INVOICE_LINENUMBER": "1"
},
"G_2": {
"VALIDATION_STATUS": "APPROVED",
"INVOICE_NUMBER": "INV_PO.060.60",
"INVOICE_LINENUMBER": "2"
}
}
}
I find working with JSON in Jython to be annoying at best, if you use JavaScript it just natively handles JSON (I mean it's in the name JavaScript Object Notation), but if you are using Python then you want to use the following. Note: I think Prashant had a typo of "loads" vs "parse".
from com.ibm.json.java import JSONObject
# This returns a JSONObject instead of the more generic JSONArtifact that the JSON.parse() function returns.
data = JSONObject.parse(inputString)
# Array processing
for g1 in data.get("G_1"):
# do your processing here.
Documentation for the com.ibm.json.java package is here for your reference https://www.ibm.com/docs/en/content-navigator/3.0.x?topic=reference-comibmjsonjava
------------------------------
Jason VenHuizen
Sharptree
------------------------------