Skip to main content

JSON Schema generation

JSON Schema is a powerful and expressive language that allows you to describe and validate the structure of JSON data. It provides a standardized way to define the format, data types, and constraints of JSON objects, enabling developers to easily share and validate data across different platforms and applications.

info

TLDR

You can generate a JSON Schema for your dcupl models via the dcupl CLI. Use this JSON schema to generate all sorts of other things like typescript types, java pojo's, documentation and so on.

# inside your dcupl project

dcupl generate json-schema

Generate code with quicktype.io using your JSON Schema

Take the generated json schema and head to https://app.quicktype.io/ - select JSON Schema on the top left as a "Source type" and your target language on the right (options). Paste your generated JSON Schema and watch quicktype do it's magic.

generate code with quicktype

Possible further things to do with JSON Schema

JSON Schema can be used to validate API payloads, ensuring that the data sent and received adheres to a predefined structure, thus improving the reliability of API endpoints. In the context of frontend development, JSON Schema can be utilized to validate user inputs and generate form UIs dynamically, streamlining the process of collecting and processing user data. It can also serve as a comprehensive documentation tool for JSON-based data models, facilitating better collaboration and understanding between developers and other stakeholders in a project.

Here's a list of projects we find quite useful in combination with JSON Schemas

  • Postman: Postman is a popular API development and testing tool that allows developers to import and export JSON Schemas. This enables users to validate API requests and responses and generate API documentation based on the schema.

  • Ajv (Another JSON Schema Validator): Ajv is a high-performance and widely-used JSON Schema validator for JavaScript that can be integrated into various projects. It supports the latest JSON Schema draft standards and offers a wide range of features, such as asynchronous validation, custom keywords, and error handling.

  • JSONSchema.net: JSONSchema.net is an online tool for generating, editing, and validating JSON Schemas. It provides a user-friendly interface that helps developers create and manage their schemas, as well as visualize the structure of their JSON data.

  • Swagger (OpenAPI): Swagger, now known as OpenAPI, is an API documentation and development framework that uses JSON Schema to describe the structure of API requests and responses. This helps developers generate client SDKs, server stubs, and API documentation in a standardized manner.

  • JSON Forms: JSON Forms is a project that uses JSON Schema to generate forms for web applications. By providing a JSON Schema, developers can create dynamic forms with automatic input validation and customizable layouts, simplifying the process of building complex forms in their applications.