This is my json object when i invoke API
job
{
"path": "/",
"isBase64Encoded": false,
"requestContext": {
"resourceId": "20gm43r4fa",
"resourcePath": "/",
"httpMethod": "POST",
"extendedRequestId": "GO6ktGL_IAMFaLA=",
"requestTime": "13/Jan/2020:09:53:34 +0000",
"path": "/",
"accountId": "***",
"protocol": "HTTP/1.1",
"stage": "test-invoke-stage",
"domainPrefix": "testPrefix",
"requestTimeEpoch": 1578909214062,
"requestId": "dgdfg-ad12-431a-b1b9-***",
"identity": {
"accountId": "***",
"caller": "345345:a.b@***.com",
"apiKey": "test-invoke-api-key",
"sourceIp": "test-invoke-source-ip",
"accessKey": "&&YY&&YH",
"userArn": "arn:aws:sts::***:assumed-role/****-PowerUser/ab.dx@****.com",
"apiKeyId": "test-invoke-api-key-id",
"userAgent": "aws-internal/3 aws-sdk-java/1.11.690 Linux/4.9.184-0.1.ac.235.83.329.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.232-b09 java/1.8.0_232 vendor/Oracle_Corporation",
"user": "345345345:Sa.b@***.com"
},
"domainName": "testPrefix.testDomainName",
"apiId": "dfgdf"
},
"resource": "/",
"httpMethod": "POST",
"body": "{\"ID\":\"sup-9749-0e710000fd04\",\"VERSION\":1,\"AUDIT_EVENT_TO_DATE_TP\":null}"
}
Body of the JSON is something like this
bodyofJson
{
"ID": "sup-9749-0e710000fd04",
"VERSION": 1,
"ACTION_TYPE": "NEW_CASE",
"EVENT_TYPE": "WORLDCHECK"
}
I need to get the body of the json and key as ID which is inside Body json . I am able to get Body but not able to get ID from body json
This is what i am doing
JSONObject job = new JSONObject(json);
System.out.println("****job*******"+job);
String bodyofJson = job.getString("body");
System.out.println("****bodyofJson*******"+bodyofJson);
The position of the ID can be changing also so thats why i am not getting based on index
Please suggest
bodyitself contains JSON, can't you just parse it as you did withjsonand get theIDfield?bodyhas value"{\"ID\":\"sup-9749-0e710000fd04\",\"VERSION\":1,\"AUDIT_EVENT_TO_DATE_TP\":null}"which you won't be able to parse as json because it's not valid (nullis not a valid value."null", notice the quotation marks, is).