You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement Get() traversing into struct{ ... } types as requested by @lestrrat:
if the type implements json.Marshaler, call MarshalJSON, convert result to json.RawMessage and then browse into that (requires Get() inside json.RawMessage #2)
else follow encoding/json mapping rules using struct tags to map the struct as if it was a map[string]interface{} (an easy (but inefficient) solution could call json.Marshal() and then follow Get() inside json.RawMessage #2)
Finally got around to considering using a new package for my json pointer needs.
Now, what I'd like to do is to apply JSON pointer semantics to a struct, namely a JSON Schema object.
I want the JSON Schema object to NOT have to be a map[string]interface{}, and I don't want to the object to have to be directly JSON-marshal-able (i.e. it has a MarshalJSON() method, but the struct definition itself is not a one-to-one mapping to the resulting JSON structure)
I think this issue means "marshal the object to JSON, then apply the logic implemented by jsonptr". Just as a thought, to avoid having to convert the struct into JSON just for this operation, would it make sense to define a type JSONGetter interface { Get(path) (interface{}, error) } or some such, to further delegate the resolution of the JSON pointer to the object itself?
Activity
lestrrat commentedon Jan 8, 2018
Finally got around to considering using a new package for my json pointer needs.
Now, what I'd like to do is to apply JSON pointer semantics to a struct, namely a JSON Schema object.
I want the JSON Schema object to NOT have to be a
map[string]interface{}, and I don't want to the object to have to be directly JSON-marshal-able (i.e. it has aMarshalJSON()method, but the struct definition itself is not a one-to-one mapping to the resulting JSON structure)I think this issue means "marshal the object to JSON, then apply the logic implemented by jsonptr". Just as a thought, to avoid having to convert the struct into JSON just for this operation, would it make sense to define a
type JSONGetter interface { Get(path) (interface{}, error) }or some such, to further delegate the resolution of the JSON pointer to the object itself?dolmen commentedon Sep 25, 2026
encoding/json/v2has now a clear specification of its mapping of structs to JSON:https://pkg.go.dev/encoding/json/v2#hdr-JSON_Representation_of_Go_structs