Skip to content

Easy reordering of JSON for consistent approvals

Compare
Choose a tag to compare
@ScottBob ScottBob released this 12 Oct 21:13
· 445 commits to master since this release

The Problem:

JSON does not define an order to the fields.
This can make approving JSON inconsistent as ApprovalTests requires consistent results.

The Solution:

JsonApprovals.verifyJson(json) now has an overload:
JsonApprovals.verifyJson(json, reorderJson: true)
which will alphabetically sort the JSON in the result.
By default it still does not reorder the JSON.

Extras

You can call the reordering directly with
JsonUtils.reorderFields(json)
This fixes #422