Generate UUID values as valid JSON strings, arrays or object fields for fixtures, API examples and seed files. JSON has no native UUID type, so identifiers must be serialized as strings and validated by the consuming application.
Key takeaways
- JSON represents UUIDs as quoted strings.
- Arrays are useful for fixtures; keyed objects are clearer when each UUID has a role.
- A JSON parser confirms syntax, while UUID validation confirms identifier shape.
For implementation context, continue with UUID CSV, Bulk UUIDs, and JavaScript. These pages cover the closest generator, comparison, validation or storage decisions without repeating this guide.
UUIDs are strings in JSON
JSON supports strings, numbers, booleans, null, arrays and objects, but not UUID as a distinct primitive. Send a canonical UUID string and let schema validation or application code enforce its format.
Avoid converting a UUID to a large JSON number. JavaScript number precision cannot safely represent all 128-bit values.
Choose an output shape
Use a JSON array when a test only needs a list of identifiers. Use objects such as {"id":"…"} when the file will grow to include status, timestamps or relationships. Consistent field names make fixtures easier to reuse.
Import and validation
Parse the JSON first, then validate each UUID and enforce uniqueness where required. A syntactically valid JSON file can still contain duplicate, nil or malformed identifiers.