-
Notifications
You must be signed in to change notification settings - Fork 207
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
error parsing unexpected type: []interface {} #17
Comments
Aha - I know where this error is: https://github.com/ChimeraCoder/gojson/blob/master/json-to-struct.go#L116 Basically, gojson tries to unmarshal it and then reflect on what the possible type is. At the top-level, JSON can either be an object or an array (slice) of objects. (It can also be a literal or So that's a bug which we definitely need to fix. In your case, though, there's still a second issue: the array appears to be heterogeneous (correct me if I'm wrong). That is, the first element has different fields from the second, third, etc., and there is a field name which distinguishes the kind - this is essentially a tagged union. In this case,
The first option is definitely doable, and I'll add a ticket for that. As a stop-gap, I'd recommend simply doing |
Thanks for the quick reply. Regarding option 1 - I can see providing both the []SuperStruct (the union) or the []SubStruct (the intersection). Regarding option 2 - While not doing much work, it is a big convenience. Seems like it would be simpler to implement. My vote would be to implement and release them in this order:
|
* Previously this would panic * Partial fix for #17
Alright, so I've updated The |
+1 need for mapping array(struct) |
Attempting to parse the JSON generated by the Reddit.com API, and ran into the following error when trying to process the JSON from:
https://www.reddit.com/r/golang/comments/2z1frh/a_jvm_writing_in_go.json
However, the JSON appears formatted correctly (it validates using http://jsonformatter.curiousconcept.com/ and http://jsonformat.com/).
The formatted JSON is:
The text was updated successfully, but these errors were encountered: