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

How to implement a "before/after" diff of a json file #12

Open
John-Colvin opened this issue Dec 7, 2020 · 2 comments
Open

How to implement a "before/after" diff of a json file #12

John-Colvin opened this issue Dec 7, 2020 · 2 comments

Comments

@John-Colvin
Copy link
Contributor

John-Colvin commented Dec 7, 2020

I want to find the difference between two json files of unknown structure, showing which entries have been added, changed and removed.

asdf.transform.AsdfNode has added and removed and that's part of the way to doing this, but actually not very convenient. Obviously I can write code to walk the AsdfNode tree by hand, but it seems like AsdfNode should be more helpful here as it's a common class of tasks

@John-Colvin
Copy link
Contributor Author

should I be looking at mir-ion instead?

@9il
Copy link
Member

9il commented Dec 8, 2020

Interesting. AsdfNode isn't good for that, Asdf number is actually a string.

We need a new type for that, like

import mir.algebraic: Nullable;
alias JsonNode = Nullable!(double, long, string, This[string], This[]);

or

import mir.algebraic: TaggedVariant;
alias TaggedJsonNode = TaggedVariant!(["null_", "float_", "integer", "string", "object", "array"],
    typeof(null), double, long, string, This[string], This[]);

Would RFC6902 work for you? For example, ruby implementation of JSON patch computation.

A possible API can look like

JsonNode jsonDiff(JsonNode from, JsonNode to)
{
    ...
}

This can be an independent algorithm from Asdf and Ion and we can implement conversion utilities between JsonNode and actual JSON backends.

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

No branches or pull requests

2 participants