3

I am using the karate framework for writing some automated test cases. I'd like to validate the schema for each element in a nested array list . For the example below, I would like to validate each child of each element in the returned array. Is there a way to get an array list of all children of all elements? I can do that by calling some java functions, but I was wondering if there's a way in karate to get that.

Something like "for each element in the returned array validate the schema of each of its children".

Thanks!

[
    {
        "id": "A",
        "children": [
            {
                "size": "10",
                "type": "A",                   
                "name": "B"
            },
            {
                "size": "10",
                "type": "A",                   
                "name": "B"
            }                            
        ]
    },
    {
        "id": "B",
        "children": [
            {
                "size": "10",
                "type": "A",                   
                "name": "B"
            }, 
            }
                "size": "3",
                "type": "C",                   
                "name": "D"
            }               
        ]
    }
]

1 Answer 1

4

match each will be more convenient for validating JSON array with a schema,

* def children = $response[*].children[*]
* def schema = { "name": "#string","size": "#string","type": "#string"}
* match each children == schema

This will extract all the values of the children and validate each child is matching with the schema

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.