Forum Discussion
- eissaeva4 years agoContributor
I am already using it as you can see from the code sample I sent but still getting the error
These are my imports
import groovy.json.JsonSlurper;
import org.json.JSONObject;- nmrao4 years agoChampion Level 3Why "import org.json.JSONObject;' is needed?
- eissaeva4 years agoContributor
this is my code - my task is to compare two JSON responses and print out their differences
If you know another approach, please share
Thanks
def printJsonObject() {
JSONObject parseJsonAct = (JSONObject) new JsonSlurper().parseText(actualResponse);
JSONObject parseJsonExp = (JSONObject) new JsonSlurper().parseText(expResponse);
for (Object key : json1.keySet()) {
//based on you key types
String keyStr = (String)key;
Object keyvalue = json1.get(keyStr);//Print key and value
log.info("key: "+ keyStr + " value: " + keyvalue);//for nested objects iteration if required
if (keyvalue instanceof JSONObject)
printJsonObject((JSONObject)keyvalue);
}
}This is the example of actualResponse - [{"inputs":[{"__typename":"ElementalField"}],"constraint":"FILE-STATUS:REPORT-STATUS:REPORT-STATUS-1='0'","source":{"sourceCodeFiles":[{"fileName":"/usr/src/workspace/PhaseChangeCreditComplex/source/cobol/PCCTRE.cob","sourceLines":[{"nodes":[{"id":"8326"}],"lineNumber":620}]}],"__typename":"Source"},"branchExecuted":false},{"inputs":[{"__typename":"ElementalField"}],"constraint":"FILE-STATUS:TRAND-STATUS:TRAND-STATUS-1='0'","source":{"sourceCodeFiles":[{"fileName":"/usr/src/workspace/PhaseChangeCreditComplex/source/cobol/PCCTRE.cob","sourceLines":[{"nodes":[{"id":"8369"}],"lineNumber":634}]}],"__typename":"Source"},"branchExecuted":false}]
Expected response is similar
Related Content
- 12 years ago
Recent Discussions
- 24 minutes ago
- 15 years ago