Home > OS >  MuleSoft - How to validate the existence of a field in a JSON?
MuleSoft - How to validate the existence of a field in a JSON?

Time:11-17

I have a component which gets JSON input, e.g.

{
  "a": "value",
  "b": null
}

I want to validate that b appears, though it can be null. So the above should pass the validation, but the following should not:

{
  "a": "value"
}

How can I do this with MuleSoft? I only found the "is not null" validation, but there doesn't seem to be any "exists" validation.

CodePudding user response:

In a DataWeave expression you can use the key present selector.

Example: payload.b?

If you use the Validation Module you can use that expression for an Is True <validation:is-true> validation operation.

  • Related