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

Get() inside structs #1

Open
dolmen opened this issue Apr 18, 2017 · 1 comment
Open

Get() inside structs #1

dolmen opened this issue Apr 18, 2017 · 1 comment
Assignees

Comments

@dolmen
Copy link
Member

dolmen commented Apr 18, 2017

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 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)
@dolmen dolmen self-assigned this Apr 18, 2017
@lestrrat
Copy link

lestrrat commented 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 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants