0

I have the following json and would like to filter few object only -

  {
    "field1": "xyz",
    "field2": "mno",
    "res1": "pqrs",
    "folder": "/folder-parent/raw/new"
  },
  {
    "field1": "xyz1",
    "field2": "mno1",
    "res1": "pqrs1",
    "folder": "/folder-parent/raw/old"
  },
  {
    "field1": "xyz1",
    "field2": "mno1",
    "res1": "pqrs1",
    "folder": "/folder-parent/changed-per-record"
  },
  {
    "field1": "xyz1",
    "field2": "mno1",
    "res1": "pqrs1",
    "folder": "/folder-parent/something-else"
  },
  {
    "field1": "xyz1",
    "field2": "mno1",
    "res1": "pqrs1",
    "folder": "/folder-parent/something/other-thing"
  }
]

I need filtered objects with /folder-parent/raw/new /folder-parent/raw/old /folder-parent/change-per-record

I tried this but does not work [ { "operation": "shift", "spec": { "*": { "folder": { "*": { "filter": "@(2, folder)=== '/folder-parent/raw/new' && @(2, folder)=== '/folder-parent/raw/old' && @(2, folder)=== '/folder-parent/change-per-record'", "": "@" } } } } } ] Please help in this case

1 Answer 1

1

Hi hope this helps you resolve your query.

Explanation : folder : the code from folder act as an if condition if folder is /folder-parent/raw/new Or /folder-parent/raw/old Or /folder-parent/changed-per-record "@2" represent to pick values as its from 2 level above it and keep it an array.

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "folder": {
          "/folder-parent/raw/new|/folder-parent/raw/old|/folder-parent/changed-per-record": {
            "@2": "[]"
          }
        }
      }
    }
  }
]
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks works , is it possible to use regex like field containing this string folder-parent?
Yes put a start "*" where ever you want to use regex. Like in previous spec you can replace the full folder like this. [ { "operation": "shift", "spec": { "*": { "folder": { "/folder-parent/r*|/folder-parent/c*": { "@2": "[]" } } } } } ] Can you please upvote and accept the answer.
accepted and upvoted! tq!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.