Structured data explained
JSON Object vs. Array and How to Validate the Shape the Consumer Expects
Try one object and a list containing that object against two JSON Schemas. Separate a root type mismatch from a problem with a list item.

At a glance
An object contains named properties. An array contains ordered values. A valid JSON object and a valid array can still fail a contract that expects the other shape.
In this guide
An object is a collection of named properties. An array is an ordered list of values. A document can use either as its root. If an importer expects one object and you send an array with one object inside, the JSON can parse successfully while the shape still fails validation.
Confirm the expected root shape
Start with the receiving contract. If it expects one record, use a schema with an object root and named properties. For this example, give the object one required property called id with an integer value. A consumer expecting multiple records can use an array root and an items schema that checks each object the same way.
Look at the parsed value rather than at the amount of data. A one-item list is still a list. A large single record can have several properties and still be one object. Set the contract so it describes what the consumer expects to take in, including whether a list may be empty.

Two shapes need two contracts
One named record
Check the root type and the properties on that object.
A list of records
Check the root array, then validate the members with an item schema.
For the JSON structure behind the comparison, see RFC 8259, JSON objects and arrays.
Sources: Understanding JSON Schema, objects · Understanding JSON Schema, arrays · IETF
Test the object and list against both contracts
Try a record with id seven and then a list containing the same record. With the single-object schema, the first example passes and the list fails at the root. With the list schema, the first example fails at the root and the list passes because its member meets the same object rule.
Now submit a list that contains one empty object. It passes the root type check. The first member fails because the required id is missing. That error points to a different location. If you only look at the fact that validation failed, you might change the whole shape when only one member needs attention.
| JSON value | Single-record schema | List-of-records schema |
|---|---|---|
| {"id":7} | Pass | Root type error |
| [{"id":7}] | Root type error | Pass |
| [{}] | Root type error | Missing id in the first item |

For array type and item schema behavior, see Understanding JSON Schema, arrays.
Sources: Understanding JSON Schema, objects · Understanding JSON Schema, arrays
Separate root and member errors
Read the error location before changing the consumer or the data. A root type failure means the first container differs from the contract. An error within item zero means the actual array was reached and the first member should be checked. Look at the required-properties rule and the actual content of that member independently.
Keep a small fixture without real account or customer data. Confirm the one-object and one-item-list cases and add an invalid member case. If you need at least one record, test an empty array as its own boundary. A correct root shape and matching rules for the contents are separate parts of the contract.


Read the error path before changing your JSON
- Confirm the contract’s root type.
- Inspect the parsed payload’s root.
- Check any member errors after resolving the root.
- Use a small anonymous fixture to test the change.
For required properties inside an object, see Understanding JSON Schema, objects.
For the related task, see Keep null and missing fields separate.
Sources: Understanding JSON Schema, objects · Understanding JSON Schema, arrays
Frequently asked questions
Is a one-item array the same as one object?
No. The array wraps a value and the position is part of the structure.
Can arrays contain objects?
Yes. A schema can require every member to satisfy an object schema.
Does items require at least one array element?
No. If the consumer needs a non-empty list, also use an appropriate minItems requirement.
Why does the instance path point to the first item?
In a validator such as Ajv, a path of /0 can identify a problem in the first member while the root array itself is valid.
Review object nesting
Check where each object sits within a bigger JSON value.
Review nested objects before validating the contractContinue with a related guide
- Review object nesting
Check where each object sits within a bigger JSON value.
- Keep null and missing fields separate
Test the value inside a correctly shaped document.
- Check the value constraints in a schema
Compare declared constraints after the root shape is right.
References
- Understanding JSON Schema, objects JSON Schema
- Understanding JSON Schema, arrays JSON Schema
- RFC 8259, JSON objects and arrays IETF