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

How to search in this case #71

Open
jet10000 opened this issue Dec 18, 2020 · 2 comments
Open

How to search in this case #71

jet10000 opened this issue Dec 18, 2020 · 2 comments

Comments

@jet10000
Copy link

json

{
    1: [
        01: {
            content: "this one"
        },
        02: {
            content: "this two"
        }
    ],
    2: [
        01: {
            content: "this three"
        },
        02: {
            content: "this four"
        }
    ]
}

I want to filter contains "two" keyword and want to return this type of result

{
    1: [
        02: {
            content: "this two"
        }
    ]
}
@jet10000 jet10000 changed the title How to search this case How to search in this case Dec 18, 2020
@darrenmothersele
Copy link

Something like this?

values(@)[*].values(@)[?contains(content, 'two')][]

https://codesandbox.io/s/cranky-flower-4ufz4?file=/src/index.js

returns:

[
  {
    "content": "this two"
  }
]

I can't think of a way of returning the exact structure you are looking for using standard JMESPath. But you might manage it using an extension like this: https://github.com/daz-is/jmespath-plus

@jet10000
Copy link
Author

I expect the returned result can retain the original json hierarchy, only need to exclude entries that do not contain keywords.

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