tjkmr
tjkmr

Reputation: 71

Validate JSON to a Particular Format

I Have a Json which may come from other application and i need to check it whether is is in particular format. The JSON template i have is as follows,

{
    "Types": {
        "Type1": {
            "attribute1": "value1",
            "attribute2": "value2",
            "attribute3": "value3",
            "recordList": {
                "record1": [
                    {
                        "field": "value"
                    },
                    {
                        "field": {
                            "subrecord1": [
                                {
                                    "subfield1": "subvalue1",
                                    "subfield2": "subvalue2"
                                }
                            ]
                        }
                    }
                ]
            },
            "date": "2010-08-21 03:05:03"
        }
    }
}

Is there any way to validate the JSON based on particular template or format.

Upvotes: 1

Views: 1502

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1073959

You can use JSON Schema for that. JSON Schema lets you describe the format of the object graph you expect to receive, and then software implementing it lets you validate what you receive against your schema. There's an OSS Java implementation called json-schema-validator.

Upvotes: 1

Related Questions