Forum Discussion
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
- nmrao4 years agoChampion Level 31. Can't find anything related to json in the link you pointed in the original question.
2. In one of your topics, i have pointed to a link to compare. Of course, that may not output as you might desired.
3. Where did you find the "Diff", "DetailedDiff" classes? Would you mind the to show the imports for the same?
4. "import org.json" has many libraries. Not sure where you got the code references.
https://mvnrepository.com/search?q=org.json
Related Content
- 12 years ago
Recent Discussions
- 11 days ago