JSON Compare

406 views
Skip to first unread message

Sapna Jayavel

unread,
Sep 14, 2023, 3:05:10 PM9/14/23
to golang-nuts
I am implementing a method find difference between two JSON objects and it has to drill down recursively. My usecase has very large nested JSON objects. Response should have the data that has changed between two JSON and position of the object. Do we have any Go package to support this?

I looked at couple of packages available out there but seems ones are not currently maintained.

Petite Abeille

unread,
Sep 14, 2023, 3:32:19 PM9/14/23
to golang-nuts


> On Sep 14, 2023, at 20:44, Sapna Jayavel <sapnaj...@gmail.com> wrote:
>
> Do we have any Go package to support this?

# diff <(gron flare-2.json) <(gron flare-3.json)
15c15
< json.children[0].children[0].children[2].value = 6714;
---
> json.children[0].children[0].children[2].value = 67144;

https://github.com/tomnomnom/gron

Corin Lawson

unread,
Sep 18, 2023, 6:14:43 AM9/18/23
to golang-nuts
What makes you say the existing packages are not maintained?  They may simply be complete?

Maxime Soulé

unread,
Sep 19, 2023, 3:15:50 AM9/19/23
to golang-nuts
Hi,

You can have a look at go-testdeep [1] and its JSON [2] operator.
go-testddep is tailored for tests, but it provides EqDeeplyError [3] function that can perhaps be useful in your use case.

json1 := json.RawMessage(`{"foo":{"a":1}}`)
json2 := json.RawMessage(`{"foo":{"b":8}}`)
err := td.EqDeeplyError(json1, td.JSON(json2))


Regards,

Max.

Reply all
Reply to author
Forward
0 new messages