I have some issues when comparing two json structures. I have to compare what is inside a json file against what is in the server so I can update the server´s info propertly.
For example:
If I have this info in the json file
{
"envs": [
{
"env": "test",
"books": [
{ "name": "book1", "read": true },
{ "name": "book2", "read": true },
{ "name": "book3", "read": true }
]
}
]
}
and getting this info from the server
{
"name": "Default",
"envs": [
"test",
"stag"
],
"books": [
{
"type": "release",
"name": "book3",
"envs": [
{
"name": "test",
"enabled": true,
},
{
"name": "stag",
"enabled": false,
}
]
},
{
"type": "release",
"name": "book4",
"envs": [
{
"name": "test",
"enabled": true,
},
{
"name": "stag",
"enabled": false,
}
]
}
]
}
So if I have in the json file book1, book2, book3 I have to compare what is the response from the server and update the info according to the json file (in the server).
For example, if I have book1, book2, book4 in the json file and book3, book2 in the server. I have just to delete book3 & include book1 and finally just inclue book4 (in the server).
I’ve tried some code with for statements but struggling to meet all the requiereemnts:
1- When the amount of books is empty in the server.
2- When the amount of books is higher than json file´s books.
3- When the amount of books in the json file is higher than books in the server’s response.
I don’t find it easy to do it with nesting for loops. Any way to achieve what I want to do or any clear example?
Thanks.