suraj das
suraj das

Reputation: 117

Validating and transform the array objects in JOLT

Would like to have the output JSON based on the active status in the input array.If active is true provide the value object. INPUT :

{
  "services": [
    {
      "active": true,
      "value": "Clampable",
      "key": "40300"
    },
    {
      "active": false,
      "value": "Mixed load",
      "key": "40302"
    }
]
}

SPECS:

[
  {
    "operation": "shift",
    "spec": {
      "services": {
        "*": {
          "key": {
            "40302": {
              "#mixed": "loading_method"
            },
            "40300": {
              "#clampable": "loading_method"
            }
          }
        }
      }
    }
  }
]

OUTPUT :

"loading_method" : [ "clampable", "mixed"]

I do not want the mixed value as output as the status is false. Any advise would be great..

Upvotes: 0

Views: 340

Answers (1)

Jagadesh
Jagadesh

Reputation: 2116

This works,

If active is true then, shift the value node.

[
  {
    "operation": "shift",
    "spec": {
      "services": {
        "*": {
          "active": {
            "true": {
              "@(2,value)": "loading_method"
            }
          }
        }
      }
    }
  }
]

Upvotes: 2

Related Questions