0

I have API that gives me every day a new JSON file, now I need to compare this JSON with my JSON to get what's new in to show updates to the user

I can get the new items and deleted items but the challenge here is how to detect the items are updated in value

API JSON
 [
  {
    "id": 10,
    "title": "delectus aut autem",
    "completed": false
  },
  {
    "id": 2,
    "title": "**som new details here i need to detect**",
    "completed": true
  },
  {
    "id": 3,
    "title": "fugiat veniam minus",
    "completed": true
  }
]

MyJSON
 [
  {
    "id": 2,
    "title": "<strike>the old data</strike>",
    "completed": false
  },
  {
    "id": 3,
    "title": "fugiat veniam minus",
    "completed": false
  }
]
ALI HUSSEIN
  • 85
  • 2
  • 9
  • 2
    Have you tried converting your JSON into a list of objects, then compare the objects? https://stackoverflow.com/questions/10404516/how-can-i-compare-lists-for-equality-in-dart – F-1 Aug 11 '19 at 16:15
  • thank u this what I need, but it did not retrieve the updated value, I will use it as a condition and compare each value in not equals items – ALI HUSSEIN Aug 11 '19 at 17:36

1 Answers1

0

I think can use zjsonpatch library to detect the differences between two json response.

A sample code:

JsonNode json1= jacksonObjectMapper.readTree(jsonString1); JsonNode json2= jacksonObjectMapper.readTree(jsonString2); JsonNode patchNode = JsonDiff.asJson(json1, json2); String diffs = patchNode.toString();