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

-subStruct does not print nested fields in array items #67

Open
satta opened this issue Jul 2, 2018 · 1 comment
Open

-subStruct does not print nested fields in array items #67

satta opened this issue Jul 2, 2018 · 1 comment

Comments

@satta
Copy link

satta commented Jul 2, 2018

I'm trying to use gojson to generate structs for an array of items, which may or may not contain (disjunct) keys with different sub-objects. Example (let's call this test.json):

[{"foo": {"bar": 2, "baz": 4, "xx": {"foo": "bar"}}}, 
 {"foo": {"bar": 2, "yy": {"bar": "baz"}}}]

In my original input these are one object per line, but as gojson can not handle this I have converted the input to an array instead. While this format can be well processed using the default settings:

$ cat test.json | gojson
package main

type Foo []struct {
	Foo struct {
		Bar int64 `json:"bar"`
		Baz int64 `json:"baz"`
		Xx  struct {
			Foo string `json:"foo"`
		} `json:"xx"`
		Yy struct {
			Bar string `json:"bar"`
		} `json:"yy"`
	} `json:"foo"`
}

there's a problem when trying to use -subStruct:

$ cat test.json | gojson -subStruct
package main

type Foo []struct {
	Foo Foo_sub3 `json:"foo"`
}

The substructs just are not printed. I would have expected an output similar to what I would get from a non-array input:

$ cat test2.json
{"foo": {"bar": 2, "baz": 4, "xx": {"foo": "bar"}}}
$ cat test2.json | gojson -subStruct
package main

type Foo struct {
	Foo Foo_sub2 `json:"foo"`
}

type Foo_sub2 struct {
	Bar int64    `json:"bar"`
	Baz int64    `json:"baz"`
	Xx  Foo_sub1 `json:"xx"`
}

type Foo_sub1 struct {
	Foo string `json:"foo"`
}

where the referenced substructs are also printed in the actual output.

@carbocation
Copy link

Just ran into this and can confirm that this is still happening.

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