THE DEV BENCH
✔️ JSON Schemahard

10. Reuse a definition with $ref

Define an "address" shape ONCE and reuse it twice. Write a schema for an object with required "billing" and "shipping", where EACH is an object with a required "street" (string) and "city" (string). Put the address shape in "definitions" and point at it with "$ref": "#/definitions/address".

How to approach this

Real schemas avoid copy-paste with "definitions" (a bag of named sub-schemas) and "$ref" (a pointer to one). "$ref": "#/definitions/address" means "validate against the schema found at /definitions/address in this document". Define the address once; reference it for both billing and shipping. (In newer drafts the bag is called "$defs" — same idea; draft-07 uses "definitions".)

schema.json