jsonptr icon indicating copy to clipboard operation
jsonptr copied to clipboard

Get() inside structs

Open dolmen opened this issue 8 years ago • 1 comments

Implement Get() traversing into struct{} as requested by @lestrrat:

  • if the type implements json.Marshaler, call MarshalJSON, convert result to json.RawMessage and then browse into that (requires #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 #2)

dolmen avatar Apr 18 '17 13:04 dolmen

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?

lestrrat avatar Jan 08 '18 12:01 lestrrat