2

I get one JSON file from an API endpoint and try to compare it to another file that is given to me. Both files are large (over a thousand lines), but the file I get from API has its values in a different order than the file I'm trying to match it to. I use Karate test framework to compare both, but it only indicates that the two files don't match. It doesn't specify exactly what differences they have. So I would like to reorder the files by myself to find the differences. Is there any kind of tool or maybe IntelliJ plugin that could help to sort/match the two files?

As an example, here's a snippet of the two files:

{
  "label": "AUD-JPY",
  "details": {
    "id": "#ignore",
    "exposureCurrency": "AUD",
    "history": {
      "entries": []
    },
    "preDecisionMetrics": {
      "exposure": {
        "gross": {
          "currency": "AUD",
          "preciseAmount": "2000.0000000000"
        },
        "hedge": {
          "currency": "AUD",
          "preciseAmount": "-3000.0000000000"
        },
        "currency": "AUD",
        "net": {
          "currency": "AUD",
          "preciseAmount": "-1000.0000000000"
        },
        "overHedge": {
          "currency": "AUD",
          "preciseAmount": "-1000.0000000000"
        }
      },
      "exposureRatio": -0.5000000000,
      "overHedge": {
        "currency": "AUD",
        "preciseAmount": "-1000.0000000000"
      },
      "vaR": {
        "gross": {
          "currency": "AUD",
          "preciseAmount": "156.94970565997420247632841778240000000000000000000000000000000000"
        },
        "net": {
          "currency": "AUD",
          "preciseAmount": "78.474852829987101238164208891200000000000000000000000000000000000000000000"
        }
      }
    },
    "postActionMetrics": {
      "exposure": {
        "gross": {
          "currency": "AUD",
          "preciseAmount": "-1000.0000000000"
        },
        "hedge": {
          "currency": "AUD",
          "preciseAmount": "0"
        },
        "currency": "AUD",
        "net": {
          "currency": "AUD",
          "preciseAmount": "-1000.0000000000"
        },
        "overHedge": {
          "currency": "AUD",
          "preciseAmount": "0"
        }
      },
      "exposureRatio": -0.5000000000,
      "overHedge": {
        "currency": "AUD",
        "preciseAmount": "0"
      },
      "vaR": {
        "gross": {
          "currency": "AUD",
          "preciseAmount": "78.474852829987101238164208891200000000000000000000000000000000000000000000"
        },
        "net": {
          "currency": "AUD",
          "preciseAmount": "39.2374264149935506190821044456000000000000000000000000000000000000000000000000000000"
        }
      }
    },
      "hedgeOwner": {
      "id": "#ignore",
      "name": "ERP1-00001-dm-api-test"
    },
    "hedge": {
      "currency": "AUD",
      "preciseAmount": "0.0000000000"
    },
    "reciprocalHedge": {
      "currency": "JPY",
      "preciseAmount": "0.0000000000"
    },
    "active": false
  },
  "children": []
}
{
  "children": [],
  "details": {
    "active": true,
    "exposureCurrency": "AUD",
    "hedge": {
      "currency": "AUD",
      "preciseAmount": "1.0000000000"
    },
    "hedgeOwner": {
      "id": "#ignore",
      "name": "ERP1-00001-dm-api-test"
    },
    "history": {
      "entries": []
    },
    "id": "#ignore",
    "postActionMetrics": {
      "exposure": {
        "currency": "AUD",
        "gross": {
          "currency": "AUD",
          "preciseAmount": "-1.0000000000"
        },
        "hedge": {
          "currency": "AUD",
          "preciseAmount": "1.0000000000"
        },
        "net": {
          "currency": "AUD",
          "preciseAmount": "0.0000000000"
        },
        "overHedge": {
          "currency": "AUD",
          "preciseAmount": "0"
        }
      },
      "exposureRatio": 0.0,
      "overHedge": {
        "currency": "AUD",
        "preciseAmount": "0"
      },
      "vaR": {
        "gross": {
          "currency": "AUD",
          "preciseAmount": "0.061274733899948203484441508788230100956032000000000000000000000000000000"
        },
        "net": {
          "currency": "AUD",
          "preciseAmount": "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000"
        }
      }
    },
    "preDecisionMetrics": {
      "exposure": {
        "currency": "AUD",
        "gross": {
          "currency": "AUD",
          "preciseAmount": "-50001.0000000000"
        },
        "hedge": {
          "currency": "AUD",
          "preciseAmount": "50000.0000000000"
        },
        "net": {
          "currency": "AUD",
          "preciseAmount": "-1.0000000000"
        },
        "overHedge": {
          "currency": "AUD",
          "preciseAmount": "0"
        }
      },
      "exposureRatio": 1.99996E-5,
      "overHedge": {
        "currency": "AUD",
        "preciseAmount": "0"
      },
      "vaR": {
        "gross": {
          "currency": "AUD",
          "preciseAmount": "3063.79797095682931080829160524360992000000000000000000000000000000"
        },
        "net": {
          "currency": "AUD",
          "preciseAmount": "0.061274733899948203484441508788230100956032000000000000000000000000000000"
        }
      }
    },
    "reciprocalHedge": {
      "currency": "CAD",
      "preciseAmount": "-1.0000000000"
    }
  },
  "label": "AUD-CAD"
}
sprogissd
  • 2,755
  • 5
  • 24
  • 45

1 Answers1

1

Please try JSON Sorter plugin for IntelliJ.

Reorder JSON Object keys. Supports Alphabetical/natural, normal/reverse, case sensitive/insensitive sort.

Eskandar Abedini
  • 2,090
  • 2
  • 13