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

include Support for JSON compare #102

Open
saikrishnaakula opened this issue Oct 13, 2020 · 5 comments
Open

include Support for JSON compare #102

saikrishnaakula opened this issue Oct 13, 2020 · 5 comments

Comments

@saikrishnaakula
Copy link

Library only work for Text can we add support for JSON

@Jav3k
Copy link

Jav3k commented Oct 22, 2020

@saikrishnaakula, did you find another react component to compare jsons ?

@dannyseo517
Copy link

Not sure if this will help you but I did this to get around it.

  <ReactDiffViewer
    oldValue={JSON.stringify(oldJson, null, 2)}
    newValue={JSON.stringify(newJson, null, 2)}
    splitView
 />

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

@Jav3k
Copy link

Jav3k commented Oct 31, 2020

@kaniseo, yeah. but you can also sort json fields and values and compare them with DiffMethod.LINES

@saikrishnaakula
Copy link
Author

Thank you, Definitly it will help but we have to take care of sorting json by keys

Not sure if this will help you but I did this to get around it.

  <ReactDiffViewer
    oldValue={JSON.stringify(oldJson, null, 2)}
    newValue={JSON.stringify(newJson, null, 2)}
    splitView
 />

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

@joshzana
Copy link

I worked around the field sorting by using https://github.com/substack/json-stable-stringify and passing in the result to ReactDiffViewer, like this:

import * as stableStringify from "json-stable-stringify";
        <ReactDiffViewer
          oldValue={stableStringify(result.before, {space: "  "})}
          newValue={stableStringify(result.after, {space: "  "})}
          compareMethod={DiffMethod.LINES}
          splitView={true}
        />

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

4 participants