Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize context JSON deterministically #414

Merged
merged 1 commit into from
May 31, 2022
Merged

Serialize context JSON deterministically #414

merged 1 commit into from
May 31, 2022

Conversation

clehner
Copy link
Member

@clehner clehner commented May 24, 2022

A recent change in the constructed/published context file consisted solely of reordering of properties:
17060ea#diff-90421741a2d21ee4772ed49f297a37c7e6ac8e0c8b28bf1bae5159816642787e
17060ea from cf24c12 (#405).

Order of the properties does not affect the meaning in JSON-LD. It was not immediately obvious to me when examining the change that there were no actual/substantive changes - until passing both the old and new version through a deterministic serialization.

Diffing the changed context file shows a large diff:

diff <(git show 17060eacf1269a565f18169b462b645612c20962:contexts/traceability-v1.jsonld) <(git show 17060eacf1269a565f18169b462b645612c20962^:contexts/traceability-v1.jsonld)

But after piping the old and new version through jq -S to sort the properties, the resulting diff is empty:

diff <(git show 17060eacf1269a565f18169b462b645612c20962:contexts/traceability-v1.jsonld | jq -S .) <(git show 17060eacf1269a565f18169b462b645612c20962^:contexts/traceability-v1.jsonld | jq -S .)

Minimizing changes that have no effect helps make diffs to the context files more readable to see what actual changes are taking place.

This PR proposes to deterministically serialize the context file serialized using json-stringify-deterministic, rather than using JSON.stringify which is not deterministic. This should help make future changes to the generated context file more readable in the commit history and diffs.

This is not a JSON-LD-significant serialization change; it is only for reducing variance in the JSON serialization, which is insignificant to JSON-LD processing (and to JSON parsing if your JSON implementation does not preserve property order).

@nissimsan nissimsan merged commit 5bd03aa into w3c-ccg:main May 31, 2022
@sbihel sbihel deleted the feat/deterministic-context-serialization branch April 29, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants