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

proposal: encoding/json: add EvalJSONPointer function to support RFC 6901 #42009

Open
baijum opened this issue Oct 16, 2020 · 3 comments
Open

proposal: encoding/json: add EvalJSONPointer function to support RFC 6901 #42009

baijum opened this issue Oct 16, 2020 · 3 comments
Labels
Milestone

Comments

@baijum
Copy link

@baijum baijum commented Oct 16, 2020

RFC 6901 describes the JSON Pointer standard.

JSON Pointer defines a string syntax for identifying a specific value within a JSON document.

More advanced query languages like JSONPath and JMESPath is not required in many cases. Also including it as part of the standard library would be an overkill.

Since JSON Pointer is a small standard, the implementation would be easy.

The API could be something like this:

func EvalJSONPointer(v interface{}, format string) ([]byte, error) {...}
@Merovius
Copy link

@Merovius Merovius commented Oct 16, 2020

I think the API needs a bit of work. AIUI it takes an arbitrary Go value and returns a []byte - so is the intent that it marshals the referenced value into JSON? ISTM that it would be more useful to return the value as a Go value. But that mainly depends on how people would want to use it - there might even be a need for different function signatures, to do different things. In particular, the RFC poses two questions that need answers: 1. How is - handled and 2. how are errors handled? Again - we might need different answers for different use-cases.

Given that, as far as I can see, nothing in the stdlib benefits from this and the implementation also doesn't benefit from coupling with internal stdlib code, I think the best course of action here is to implement this outside the stdlib to experiment with the API and re-consider the benefits of including it once kinks in the API has been shaken out.

@odeke-em odeke-em changed the title enconding/json: add EvalJSONPointer function to support RFC 6901 proposal: encoding/json: add EvalJSONPointer function to support RFC 6901 Oct 16, 2020
@gopherbot gopherbot added this to the Proposal milestone Oct 16, 2020
@gopherbot gopherbot added the Proposal label Oct 16, 2020
@mvdan
Copy link
Member

@mvdan mvdan commented Oct 16, 2020

I agree with Axel; implement this outside of the standard library first. https://golang.org/doc/faq#x_in_std

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.