1

I have the below JSON and need to filter based on field

[
  {
    "firstname": "ABC",
    "lastname": "PQR",
    "id": 1,
    "address": {
      "city": "LA",
      "zipcode": "123",
      "addressType": "Home",
      "status": "Active"
    },
    "department": {
      "id": "12",
      "manager": "tyx",
      "extraInfo": "N/A"
    }
  },
  {
    "firstname": "MNO",
    "lastname": "LLL",
    "id": 2,
    "address": {
      "city": "TX",
      "zipcode": "234",
      "addressType": "Home",
      "status": "Active"
    },
    "department": {
      "id": "123",
      "manager": "tyxx",
      "extraInfo": "N/A"
    }
  }
]

I use the below jolt spec

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "address": {
          "status": {
            "Active": {
              "@2": "[]"
            }
          }
        }
      }
    }
  }
]

which gives Jolt spec test

I need the whole JSON not only field from address, I would like to have first name, last name,id and department in output ,please help.

1 Answer 1

1

You can start with nesting other elements within an others object, and go on like this :

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].others.&",
        "address": "[&1].&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "address": {
          "status": {
            "Active": {
              "@3,others": { "*": "&5.&" },
              "@2": "&4.&3"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "[]"
    }
  }
]

the demo on the site Jolt Transform Demo Using v0.1.1

( Notice below that the second status is Inactive within my demo example ) :

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks , but If do with 3 json records I get null for InActive status
can you pls have a look?
Yes, you're right @DotNetDev19 , just fixed it.

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.