Re: [go-nuts] Detecting JSON changes

2022-10-10 Thread Shulhan
On Mon, 10 Oct 2022 07:50:20 -0700 (PDT)
Slawomir Pryczek  wrote:

> Hi Guys,
> I have 2 json files, A, B. Now i want to detect changes on the root
> level.
> 
> File A: {"a":{"b":1, "c":2}, "x":false,  ... }
> File B: {"a":{"b":1, "c":2}, "x":true,  ... }
> 
> I want to be able to see that x is different between A and B and a
> stayed the same. What would be the easiest approach?
> 
> Thanks
> 

I can think three options here.

One, create a type T that unmarshal the JSON into T and add method that
compare each fields.

Two, create a type T and unmarshal the JSON into T and use third party
library that do struct comparison.

Three, diff the text as is using third party library.

For option two and three, I have some example here:

https://go.dev/play/p/bknJBK4m4CW

-- ms

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20221010221608.0518b78f%40inspiro.localdomain.


pgpybFhctz21m.pgp
Description: OpenPGP digital signature


Re: [go-nuts] Detecting JSON changes

2022-10-10 Thread burak serdar
On Mon, Oct 10, 2022 at 8:50 AM Slawomir Pryczek 
wrote:

> Hi Guys,
> I have 2 json files, A, B. Now i want to detect changes on the root level.
>
> File A: {"a":{"b":1, "c":2}, "x":false,  ... }
> File B: {"a":{"b":1, "c":2}, "x":true,  ... }
>
> I want to be able to see that x is different between A and B and a stayed
> the same. What would be the easiest approach?
>

This is not easy in general. Try using an available package, like:
github.com/wI2L/jsondiff


>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/7e88ac99-b6ff-49af-95a9-c1c5d7cf9236n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMV2RqohB%3DrtvNLWwtL0MOrNHf%3Deu0j%2BYm0NsQJi14nfc_W--A%40mail.gmail.com.


[go-nuts] Detecting JSON changes

2022-10-10 Thread Slawomir Pryczek
Hi Guys,
I have 2 json files, A, B. Now i want to detect changes on the root level.

File A: {"a":{"b":1, "c":2}, "x":false,  ... }
File B: {"a":{"b":1, "c":2}, "x":true,  ... }

I want to be able to see that x is different between A and B and a stayed 
the same. What would be the easiest approach?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7e88ac99-b6ff-49af-95a9-c1c5d7cf9236n%40googlegroups.com.