Skip to content

question: How to parse a path? #169

Closed
@krombel

Description

@krombel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions