Skip to content

question: How to parse a path? #169

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

Closed
krombel opened this issue Apr 14, 2025 · 2 comments
Closed

question: How to parse a path? #169

krombel opened this issue Apr 14, 2025 · 2 comments

Comments

@krombel
Copy link

krombel commented Apr 14, 2025

I would like to be able to only parse a specific path in the json object.

e.g.

{
  "a": {
    "b1": {
      "test": "something"
    },
    "b2": {
      "test": "something else"
    }
  }
}

I would like to provide e.g. a.b2.test and would like to get "something else".

This is useful in scenarios where I am only interested in one specific attribute from a probably big json object.
With encoding/json I built a workaround which looped through each "layer" and parsed the object to a map[string]json.RawMessage which I then parsed until the leaf object.
Is there an easy (and opt. more performant) way here? I would like to have a way without the need of parsing the whole input when I only need a few bytes of it.

@dsnet
Copy link
Collaborator

dsnet commented Apr 14, 2025

Hi, thanks for the question. I think what you're asking for is related to a recent comment over at golang/go#71497 (comment)

There's already JSON Pointer [RFC 6901], which json/v2 is currently using to report error positions. However, it currently doesn't provide any means of going from a jsontext.Pointer to a particular jsontext.Value.

@dsnet
Copy link
Collaborator

dsnet commented Apr 14, 2025

I'm going to close this. It's something worth potentially adding to json/v2 in the future, but that would probably be discussion to be held over in the golang/go repo.

@dsnet dsnet closed this as completed Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants