Skip to main content
QUICK REVIEW

[Paper Review] Type Safety with JSON Subschema

Andrew Habib, Avraham Shinnar|arXiv (Cornell University)|Nov 28, 2019
Software Engineering ResearchComputer Science21 references4 citations
TL;DR

This paper presents jsonsubschema, a formal and implemented subschema checker for JSON Schema that enables static type safety by determining whether one schema is a subschema of another. By canonicalizing and simplifying schemas, then decomposing them into type-specific fragments, the approach efficiently and correctly checks subschema relationships across complex features like regular expressions, multipleOf constraints, and schema composition, demonstrating effectiveness on 8,548 real-world schema pairs.

ABSTRACT

JSON is a popular data format used pervasively in web APIs, cloud computing, NoSQL databases, and increasingly also machine learning. JSON Schema is a language for declaring the structure of valid JSON data. There are validators that can decide whether a JSON document is valid with respect to a schema. Unfortunately, like all instance-based testing, these validators can only show the presence and never the absence of a bug. This paper presents a complementary technique: JSON subschema checking, which can be used for static type checking with JSON Schema. Deciding whether one schema is a subschema of another is non-trivial because of the richness of the JSON Schema specification language. Given a pair of schemas, our approach first canonicalizes and simplifies both schemas, then decides the subschema question on the canonical forms, dispatching simpler subschema queries to type-specific checkers. We apply an implementation of our subschema checking algorithm to 8,548 pairs of real-world JSON schemas from different domains, demonstrating that it can decide the subschema question for most schema pairs and is always correct for schema pairs that it can decide. We hope that our work will bring more static guarantees to hard-to-debug domains, such as cloud computing and artificial intelligence.

Motivation & Objective

  • To address the lack of static guarantees in JSON-based systems where runtime validation is error-prone and costly.
  • To enable early detection of breaking changes in evolving web APIs and machine learning pipelines.
  • To provide a correct and scalable solution for determining whether one JSON schema is a subschema of another, despite the expressive complexity of JSON Schema.
  • To support safer, more reliable software development in domains like cloud computing and AI, where data structure mismatches lead to hard-to-debug failures.

Proposed method

  • Canonicalize and simplify both input schemas to eliminate syntactic and structural redundancies while preserving semantic meaning.
  • Decompose schemas into type-homogeneous fragments based on their underlying data types (e.g., string, number, array, object).
  • Dispatch each fragment to a specialized type-specific checker that evaluates subschema relationships for that type.
  • Use a compositional approach to combine results from individual fragment checks, ensuring correctness across complex schema constructs.
  • Leverage formal semantics of JSON Schema to ensure soundness and completeness for all decidable cases.
  • Apply the algorithm to 8,548 real-world schema pairs from diverse domains, including web APIs, cloud services, and ML pipelines.

Experimental results

Research questions

  • RQ1Can a formal and efficient subschema checker be built for JSON Schema despite its rich and complex type system?
  • RQ2How effective is the approach in handling challenging features such as regular expressions, multipleOf constraints, and schema composition with negation and unions?
  • RQ3Can the checker scale to real-world schema sets while maintaining correctness and performance?
  • RQ4To what extent can subschema checking prevent runtime failures in cloud and AI systems by enabling static validation?

Key findings

  • The jsonsubschema tool successfully decides the subschema relationship for the vast majority of the 8,548 real-world schema pairs evaluated.
  • The tool is always correct for schema pairs it can decide, ensuring soundness in all cases.
  • The canonicalization and fragment-based decomposition strategy effectively handles complex schema features like regular expressions, multipleOf, and schema composition.
  • The approach enables static detection of breaking changes in web APIs and ML pipelines before deployment, reducing runtime failures and debugging overhead.
  • The method outperforms naive structural or lexical comparisons, which are insufficient due to the expressiveness of JSON Schema.
  • The evaluation confirms that subschema checking is both feasible and practical for production systems in cloud computing and AI.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.