Skip to content

How do I retrieve all values when nested dictionaries are present? #386

@dnj12345

Description

@dnj12345

Hi,
I am using https://gjson.dev/ to test the gjson library.

For the json shown below, I was providing the path as Nicknames.*.last. I get the result Andy Trevor. I was expecting it to return an array of values like [ "Andy Trevor", "Roger Binny" ]. When the target is an array, I can write the expression like thisfriends.#.last which returns ["Murphy","Craig","Murphy"].

The documentation describes # to refer to all elements of an array, but doesn't mention anything for dictionary of dictionary. I used * but that doesn't do I exected. Is what I am trying to do possible? Thanks.

Dk.

{
  "name": {"first": "Tom", "last": "Anderson"},
  "age":37,
  "children": ["Sara","Alex","Jack"],
  "fav.movie": "Deer Hunter",
  "Nicknames":{
     "home":{
        "last":"Andy Trevor"
      },
      "work":{
         "last":"Roger Binny"
      }
  }, 
  "friends": [
    {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
    {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
    {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions