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

Grep "key: value" by key #59

Open
techtonik opened this issue Jan 23, 2019 · 5 comments
Open

Grep "key: value" by key #59

techtonik opened this issue Jan 23, 2019 · 5 comments

Comments

@techtonik
Copy link

Is it possible to get all authors regardless of their location in a document?

In JSONPath it will be $..author, in jq ..|objects.author. What is the equivalent for JMESPath?

{ "store": {
    "book": [ 
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      },
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}

Trying to understand it by comparing to known tools https://github.com/stedolan/jq/wiki/For-JSONPath-users

@Thaina
Copy link

Thaina commented Aug 31, 2019

In my current understanding of JMESPath, there are no way you could traverse any number of depth. It is a feature that specifically removed from JsonPath. You can only flatten it into some finite number of depth

Maybe [*][*][*].author is what you could do

@techtonik
Copy link
Author

techtonik commented Sep 3, 2019

@Thaina checked [*][*][*].author with http://jmespath.org/tutorial.html and it doesn't work. Seems like the only supported syntax is name[*] for flattening arrays, so you need to know the name. For this particular case store.book[*].author helps to get authors, but that's not a grep that could be used if the document structure is unknown.

@Thaina
Copy link

Thaina commented Sep 3, 2019

@techtonik Maybe this?
image

@Thaina
Copy link

Thaina commented Sep 3, 2019

You might need to write a long list of every possible combination of flattening and flatten it

image

@techtonik
Copy link
Author

*.*[*].author. The structure is still there, but at least no need to retype names.

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