java - Comparing Json Template with JSON Response -


(the following has been edited make understandable.)

we want compare actual json object expected json object, complication json objects may contain other json objects. using net.sf.json api this. have tried following approaches:

  1. we have tried json objects' keys lists (to preserve keys' order) , indexes of keys in lists.

  2. we have tried adding (flattening) keys , values in json objects pair of map objects. in case, had problems duplicate keys in nested json objects. addressed making values in map lists of values json objects.

after discussion team, need modify approach follows:

(the following has not been edited ...)

now wanna compare key , values in result json , expected json (must need check format) while traversing each key in result json parallelly want check same(key , value) in expected json.

first of all, if preserving order of keys in json objects because order important meaning of json, abusing json. json specs make clear order of key in json object should not significant. lot of json implementations not preserve key order when deserializing, , ... indeed ... may not able of representing order.

if have made conceptual mistake, should fix before late (!). if need represent order, use json array that.

assuming aren't trying that, here simple approach encoding json object trees map objects. instead of using map<string, list<object>> keys json keys, use map<string, object> keys formed concatenating keys in path json root; e.g.

    {a: {b : "c",          d : "e"}} 

becomes map.

    {"a.b" = "c",      "a.d" = "e} 

now don't have deal lists of values, ordering of those, or other problems have encountered. instead can sort map's entry set on composite keys, , compare them looking missing or entries, or entries wrong value.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -