Assert with a json that contains a json

⚓ rust    📅 2025-05-05    👤 surdeus    👁️ 8      

surdeus

Warning

This post was published 60 days ago. The information described in this article may have changed.

Hi !

I would like to ask you if some tools already exists as I wanted to go further with tests on json for example. There are assert_json! and validators that allow you to check the consistency of some of the fields. Is there a way to check if a json contains a value? For example with the data not known in advance of a json like this?

{
    "data": {
        "A": {
            "B": {
                "C": [
                    {
                        "id": "1",
                        "description": "desc 1"
                    },
                    {
                        "id": "2",
                        "description": "desc 2"
                    }
                ]
            }
        }
    }
}

I just want to check if the following is in the array ? Like if the first one contains this one...

{
    "data": {
        "A": {
            "B": {
                "C": [
                    {
                        "id": "1",
                        "description": "desc 1"
                    }
                ]
            }
        }
    }
}

Kind of :

let json1 = // first json
let json2 = // second json

json1.contains(json2) -> bool ?

Maybe, I can have other example where it is not an array we check... Just that one contains the data of the other as least... Or the reverse operation... the second is in the first one ?

json2.is_in(json1) -> bool ?

3 posts - 3 participants

Read full topic

🏷️ rust_feed