Skip to content

Cleaner JSON schema with inline bool and string types#2476

Merged
stephenberry merged 1 commit intomainfrom
jsonschema-inline-bool-string-types
Apr 13, 2026
Merged

Cleaner JSON schema with inline bool and string types#2476
stephenberry merged 1 commit intomainfrom
jsonschema-inline-bool-string-types

Conversation

@stephenberry
Copy link
Copy Markdown
Owner

@stephenberry stephenberry commented Apr 13, 2026

Inline JSON Schema for bool, string, and optional variants

Resolves #2473

Summary

Primitive types (bool, std::string, std::string_view, char) and their std::optional wrappers are now inlined directly in JSON Schema properties instead of being placed in $defs and referenced via $ref.

Before:

{
  "properties": {
    "name": { "$ref": "#/$defs/std::string" },
    "flag": { "$ref": "#/$defs/bool" }
  },
  "$defs": {
    "std::string": { "type": "string" },
    "bool": { "type": "boolean" }
  }
}

After:

{
  "properties": {
    "name": { "type": "string" },
    "flag": { "type": "boolean" }
  }
}

Nullable variants inline with the "null" type added:

{
  "nickname": { "type": ["string", "null"] }
}

Per-field metadata from json_schema is preserved alongside the inlined type:

{
  "name": { "type": "string", "description": "A name for something" }
}

Changes

  • include/glaze/json/schema.hpp: Added a type field to glz::schema so properties can express {"type":"..."} directly. Modified the object handler to inline bool, str_t/char_t, and nullable_t wrappers of those types instead of creating $defs/$ref entries. If a user explicitly sets $ref via json_schema metadata, that is still respected.
  • Tests: Updated expected schema strings across 6 test files to reflect the new inlined output.

@stephenberry stephenberry merged commit 6455693 into main Apr 13, 2026
48 of 49 checks passed
@stephenberry stephenberry deleted the jsonschema-inline-bool-string-types branch April 13, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema Optimization: Always Inline bool, std::string and std::optional?

1 participant