AlexH
AlexH

Reputation: 157

How to validate json schema for a particular naming?

Updated:

Please, take a look at following.

For this example, it has two pretty the same objects inside. With two fields for each of them - id and is_deleted.

{
    "meta": {
        "delete_count": 1,
        "status": [
            {
                "id": 1,
                "is_deleted": true
            },
            {
                "id": 2,
                "is_deleted": false
            }
        ]
    }
}

Let's imagine 2 different occasions:

So, I have a schema for this payload. But, it checks for field types not for field names.

it uses com.jayway.restassured.module.jsv

Upvotes: 0

Views: 62

Answers (2)

Dipankar Baghel
Dipankar Baghel

Reputation: 2039

JsonObject has a method which returns true if key exist public boolean has(java.lang.String key)

JSONObject jsonObj = new JSONObject(Your_STRING);
if (jsonObj.has("org_id")) {
      //Do stuff
}

for more details you can check below -

check key exist

Upvotes: 1

ramzieus
ramzieus

Reputation: 157

try to verify if org_id exists, the question isn't clear!.

Upvotes: 0

Related Questions