Hi Manideep,
You can achieve this using DFDL JSON schema. On the HTTP Input node, you need to configure
- Message Domain: JSON
- Message Model: Your json schema
- Parser Options: Parser timing = Complete/Immediate
- Validation: Content and Value
Below is the schema definition for your requirement:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"name": { "type": "string" },
"credit_card": { "type": "number" },
"mobile": { "type": "number" }
},
"required": ["name"],
"dependencies": {
"credit_card": {
"additionalProperties": {
"allOf": [
{"address1": { "type": "string" }},
{"address2": { "type": "string" }},
{"expiry": { "type": "string" }}
]
},
"required": ["address1","address2","expiry"]
}
}
}
Sample Test Message:
{
"name": "John Doe",
"credit_card": 790054009987,
"address1": "66666, Prescott St",
"address2": "Massachusetts,94955",
"expiry": "03/25",
"mobile": 8230832040
}
Thanks
Uvaise Ahmed
------------------------------
uvaise odam
------------------------------
Original Message:
Sent: Thu June 20, 2024 02:59 AM
From: Manideep vusakoila
Subject: Conditional Mandatory Field Validation in JSON Request Using ESQL/DFDL
Hi,
I have a requirement to validate a JSON request with conditional mandatory fields. This means if a JSON request has 5 fields and the first field exists, then the second and third fields must also exist. How can we achieve this using ESQL without using if conditions? Is there any way to handle this in DFDL?
Kindly suggest a solution to complete this. Thanks in advance.
------------------------------
Manideep vusakoila
------------------------------