Jeffail/gabs

Is it possible to retrieve the structure of a JSON document without array indices?

mdelapenya opened this issue · 2 comments

I've used Flatten to get the structure of a JSON, with the main goal of comparing two JSON objects structure, but I see differences because there are different number of array elements in both documents. I created a Go playground example here (https://play.golang.org/p/j_k0F2yM66I) demonstrating this behavior.

json1

{
	"a": {
		"array": [
			{"c": "c11"},
			{"c": "c12"}
		]
	},
	"b": "b1"
}

json 2

{
	"a": {
		"array": [
			{"c": "c21"},
			{"c": "c22"},
			{"c": "c22"}
		]
	},
	"b": "b2"
}

While the current Flatten method returns a map with this:

// json1
a.array.0.c
a.array.1.c
b

// json2
a.array.1.c
a.array.2.c
b
a.array.0.c

I would like to have just simply the structure, so I can determine if bot JSON files has the same structure:

// json1
a.array.c
b

// json2
b
a.array.c

Is is possible?

Hey @mdelapenya, you could do this in a slightly hacky way by trimming the pattern .[0-9]+ from the output paths, but unfortunately I don't think there's a proper way of doing this right now.

Yeah, I was thinking about that workaround too 🤔

BTW, great tool, I'm using it extensively for dynamic JSON processors and it works great!!