4
donuts
4y

I need to compare the JSON results of an API before and after a code change. But it was also moved to another API.

However some fields are auto-generated like timestamp or derived off the url (resource links).

Also if a JSON list is returned it maybe in different order...

Wondering is there a quick way to test text likeness?

I've done it before but just used matching status code and maybe measuring the diff in response size

Comments
  • 0
    do you need that as a continous service or a one time comparison?
  • 0
    Fastest and easiest way would probably be to parse and compare all fields.
  • 0
    I would say write two mapping functions and an injector that serves them keyed off the api version.

    But, given they don't seem to have static schemas, they probably also don't have API versions.
  • 1
    @heyheni one off for now
  • 1
    @olback how? You have 2 list of objects, different orders. Though I guess if we modify both versions to sort the results by Id that'd work for this specific case.

    Sorting after db is hard, some results are huge...

    But actually just realized for my case all I need to check is the IDs are the same...
  • 1
    @billgates maybe? http://www.jsondiff.com/

    if commandline is more your thing
    https://github.com/andreyvit/...

    There is probably a function in jsonlint in the vscode extension or vscode itself.
  • 0
    Throw it through jq and then diff?
Add Comment