1

What would be the proper way to create the match string in the case below?

I am stuck with the correct match string which would validate both of the below JSON(s).

In one of them, we have the "Periods" data,

{
    "id": 1,
    "period":
    [
        {
            "startDate": "2022-05-05",
            "endDate": "2022-05-06"
        },
        {
            "startDate": "2022-06-05",
            "endDate": "2022-06-06"
        }
    ]
}

on the other its a null array.

{
    "id": 1,
    "period": []
}

I have been trying with the below match string but the same seems to fail

* match response contains deep "##({period: [{startDate: '#notnull'}]})"

1 Answer 1

1

Here you go:

* def dateSchema = { startDate: '#string', endDate: '#string' }
* match response == { id: '#number', period: '#[] dateSchema' }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @peter. This worked marvelously. made a minor change to match * match response == { id: '#number', period: '##[] dateSchema' } to cater the scenario if the key is not sent. Thank you.

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.