0

Given a collection (not an array) like this:

{
  "field1": {
    "type": "string",
    "value": "test"
  },
  "field2": {
    "type": "array",
    "value": []
  },
  "field3": {
    "type": "string",
    "value": "test"
  },
  "field4": {
    "type": "array",
    "value": []
  }
}

how do I end up with just (filtering on type="array"):

{
  "field2": {
    "type": "array",
    "value": []
  },
  "field4": {
    "type": "array",
    "value": []
  }
}

1 Answer 1

0

The JSONata wildcard operator will select the values of all fields in the context object.

Option 1

$map($spread($), function($x){
  $x.*.type = 'array' ? {
    $keys($x): $x.*
  }
})

JSONata Playground: https://jsonatastudio.com/playground/f5648325

Option 2

$.*[type="array"]

The output will look like:

[
  {
    "type": "array",
    "value": []
  },
  {
    "type": "array",
    "value": []
  }
]

JSONata Playground: https://jsonatastudio.com/playground/3007924a

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

Comments

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.