JSON Schema default Is an Annotation, Not a Population Step

Riddle

A schema says the retries property has a default of 3. The input instance is {}. Validation succeeds.

What should you expect the instance to contain afterward?

Answer

Still {}.

In JSON Schema, default describes a value associated with a particular schema. It does not, by itself, insert that value into the instance. Validation can accept a missing optional property without turning absence into 3.

That makes two separate questions easy to confuse. Is retries allowed to be absent? And if it is absent, should the application populate it? The schema can answer the validation question. Population is an application behavior that needs its own explicit step.

The JSON Schema Draft 2020-12 validation specification, published 16 June 2022, places default among the basic metadata annotations. It says the keyword supplies a default JSON value associated with a particular schema and recommends that the value be valid against that schema.

During evaluation, non-assertion information can be collected as annotation output at an instance location where a schema applies. That evaluation result still does not mutate the instance or create a missing property.

Q&A

Does required make the default appear?

No. Marking retries as required makes {} fail validation; it still does not populate the property.

Can a library offer default-filling anyway?

A library or wrapper can add that application behavior, but it should be treated as an explicit population feature rather than assumed from the schema keyword. Its timing matters too: populate first and validate the resulting instance if downstream code depends on the populated value.

What is the small implementation trap?

Do not use truthiness as a substitute for absence. An expression such as value || 3 replaces legitimate values including 0 and false. Check whether the property is actually absent, then apply 3, then validate the result.

Where, in your application, is the explicit population step that turns a missing retries property into 3 before the next validation pass?

A useful implementation guardrail is to make population a deterministic, observable transformation rather than a hidden validator option. For example, let populate(instance, policy) return both a new instance and the JSON Pointer paths it inserted, then validate that returned instance separately.

That boundary also exposes failure cases that a generic “walk the schema and copy every default” pass can hide. A default inside a conditional or combined subschema should not be copied merely because the keyword exists somewhere in the schema tree; whether that subschema applies is part of evaluation. The application therefore needs an explicit policy for branch selection instead of treating every annotation as an instruction.

I would test the population step for absence versus null, branch selection, invalid configured defaults, and idempotence: applying it twice should produce the same instance and no new inserted paths on the second pass. Those checks keep mutation policy testable without changing what schema validation itself means.