{
"service": "CURBSIDE",
"unavailableLines": {
"unavailableLine": [
{
"unavailableQty": "10.0",
"itemLineId": "4",
"unavailableReasonCode": "NOT_ENOUGH_PRODUCT_CHOICES"
},
{
"unavailableQty": "5.0",
"itemLineId": "3",
"unavailableReasonCode": "NOT_ENOUGH_PRODUCT_CHOICES"
}
]
},
"id": "HD2",
"deliveries": {
"delivery": [
{
"serviceItemId": "SGR40400002",
"deliveryId": "1",
"unitOfMeasure": "ORDERS"
},
{
"serviceItemId": "SGR40400003",
"deliveryId": "2",
"unitOfMeasure": "ORDERS"
},
{
"serviceItemId": "SGR40400002",
"deliveryId": "3",
"unitOfMeasure": "ORDERS"
}
]
},
"earliestShipDate": "2018-12-03T07:00:00.000Z"
}
]
The above is an JSON Object. I am trying to extract the values by using the below code in JSR223 processor:
//dumps the json object into an element
json_str = json.dumps(newJson3)
//load the json to a string
resp = json.loads(json_str)
//print the resp
log.info(resp)
//extract an element in the response
print (resp['unavailableQty'])
I am getting error response, kindly some one help me to reterive all the values from the Json Object
Find the error that I am getting while using the below script
json_str = json.dumps(newJson3)
resp = json.loads(json_str)
log.info(resp)
print (resp['unavailableQty'])
Error:
javax.script.ScriptException:
========Error================================================
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such
property: json for class: Script622 at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158) ~[groovy-all-2.4.12.jar:2.4.12] at javax.script.AbstractScriptEngine.eval(Unknown Source) ~[?:1.8.0_171] –
log.info(resp)
return, and what is your error message?