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

getModifiedDiff() #25

Closed
karam-naser opened this issue Sep 28, 2019 · 4 comments
Closed

getModifiedDiff() #25

karam-naser opened this issue Sep 28, 2019 · 4 comments

Comments

@karam-naser
Copy link

i'm sending those 2 json objects
{"output": [{"text": "قَلَم", "type": "text"}], "answers": [{"text": "ـم", "correct": true}, {"text": "م", "correct": false}, {"text": "ـمـ", "correct": false}, {"text": "مـ", "correct": false}], "question": [{"text": "قَلَـ....", "type": "text", "translation": ""}], "answersType": "text", "questionText": "Harfin uygun yazılışını seçiniz"}

{"questionText":"Harfin uygun yaz\u0131l\u0131\u015f\u0131n\u0131 se\u00e7iniz","question":[{"type":"text","text":"\u0642\u064e\u0644\u064e\u0640....","translation":"","upload":""}],"answersType":"text","answers":[{"text":"\u0640\u0645","correct":true,"upload":"a0vA206.mp4","image":""},{"text":"\u0645","correct":false,"upload":"a0vA207.mp4","image":""},{"text":"\u0640\u0645\u0640","correct":false,"upload":"","image":""},{"text":"\u0645\u0640","correct":false,"upload":"","image":""}],"output":[{"type":"text","text":"\u0642\u064e\u0644\u064e\u0645","upload":""}]}

and using jsonDiff with this flags
JsonDiff::REARRANGE_ARRAYS + JsonDiff::COLLECT_MODIFIED_DIFF

when i call getModifiedDiff() it showed null array even it's obvious there is a difference between 2 json

@vearutop
Copy link
Member

vearutop commented Sep 28, 2019

getModifiedDiff() is expected to return a list of paths that exist in both JSON documents with different values.

In your example second document does not seem to modify any value existing in first document, but rather adds new values.

Maybe you need to use getAdded() or getAddedPaths() instead of getModifiedDiff() in this case.

Here is getPatch() from first to second document:

[
    {
        "value": "",
        "op": "add",
        "path": "/output/0/upload"
    },
    {
        "value": "a0vA206.mp4",
        "op": "add",
        "path": "/answers/0/upload"
    },
    {
        "value": "",
        "op": "add",
        "path": "/answers/0/image"
    },
    {
        "value": "a0vA207.mp4",
        "op": "add",
        "path": "/answers/1/upload"
    },
    {
        "value": "",
        "op": "add",
        "path": "/answers/1/image"
    },
    {
        "value": "",
        "op": "add",
        "path": "/answers/2/upload"
    },
    {
        "value": "",
        "op": "add",
        "path": "/answers/2/image"
    },
    {
        "value": "",
        "op": "add",
        "path": "/answers/3/upload"
    },
    {
        "value": "",
        "op": "add",
        "path": "/answers/3/image"
    },
    {
        "value": "",
        "op": "add",
        "path": "/question/0/upload"
    }
]

Does this help your issue?

@karam-naser
Copy link
Author

karam-naser commented Sep 29, 2019

thanks for your answer
if you look at answers you see the difference
1st json:
answers": [{"text": "ـم", "correct": true}, {"text": "م", "correct": false}, {"text": "ـمـ", "correct": false}, {"text": "مـ", "correct": false}], "question": [{"text": "قَلَـ....", "type": "text", "translation": ""}],
2nd json:
"answers":[{"text":"\u0640\u0645","correct":true,"upload":"a0vA206.mp4","image":""},{"text":"\u0645","correct":false,"upload":"a0vA207.mp4","image":""},{"text":"\u0640\u0645\u0640","correct":false,"upload":"","image":""},{"text":"\u0645\u0640","correct":false,"upload":"","image":""}]

the bolded section not exist in the one

@karam-naser
Copy link
Author

i've made a function to delete null values from both JSONs and then call getPatch() and it's worked now.
I can find if there's any difference between them

@vearutop
Copy link
Member

the bolded section not exist in the one

Yes, and because of that these sections do not contribute to getModifiedDiff(), they are additions, not modifications (in terms of JsonDiff).

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