0

I am trying to exclude some fields from Json by jsonPath expression but it doesnt works. I am not able to write properly expression that match just some fields, without excluded.

I have tried to use somethink like this $.personal.[?(!@.email)] but it not works.

I have json like this:

{
  "personal": {
    "fullName": "full Name",
    "firstName": "first Name",
    "email": "hello@email.com"
    }
}

I tried to use this line to select fields without email field:

$.personal.[?(!@.email)]

But i got only this results or false:

[
  "full Name",
  "first Name",
  "hello@email.com"
]

I would like to have results like this:

[
  "full Name",
  "first Name"
]

1 Answers1

0

As far as I know, you cannot exclude a property (ie. a blacklist approach), but you can select which properties to include (ie. a whitelist approach).

In this second case, any properties you leave out are not captured by the query.

So in your example,

$.personal.['fullname','firstname']

is what you need. Its not quite the same thing because you may not know the property names ahead of time