DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Exploring JSON Schema for Form Validation in Web Components
  • Datafaker Gen: Leveraging BigQuery Sink on Google Cloud Platform
  • Validate XML Request Against XML Schema in Mule 4
  • Validate JSON Request Against JSON Schema in Mule 4

Trending

  • Creating a Web Project: Caching for Performance Optimization
  • The End of “Good Enough Agile”
  • SaaS in an Enterprise - An Implementation Roadmap
  • Modern Test Automation With AI (LLM) and Playwright MCP
  1. DZone
  2. Coding
  3. Languages
  4. Publishing JSON Schema Documentation With Docson

Publishing JSON Schema Documentation With Docson

Trying to communicate using JSON files or messages? Here is a tool that will make it easier to share how the JSON should be constructed, without leaving a code editor and browser.

By 
Alan Hohn user avatar
Alan Hohn
·
Mar. 17, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
17.6K Views

Join the DZone community and get the full member experience.

Join For Free

For systems that have JSON data that's published as part of an API, there are tools such as Swagger/OpenAPI and RAML that can be used to define REST endpoints and the data types for requests and responses. However, for cases where JSON data isn't part of a REST API, such as documents in MongoDB, files on a disk, or messages, JSON Schema provides a way to specify what the JSON will look like in a way that covers all the possibilities better than making example documents.

JSON Schema is itself a JSON document with pre-defined properties and types. For example, a simple JSON schema might look like this:

{
    "description": "Mailing address schema",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "required": ["name", "zip"],
    "properties": {
        "name": {
            "description": "Full name of the recipient",
            "type": "string"
        },
        "addressType": {
            "description": "Whether the address is a residence, a business, or a post office box",
            "enum": ["residence", "business", "pobox"]
        },
        "street": {
            "description": "Street address and number",
            "type": "string"
        },
        "city": {
            "description": "City",
            "type": "string"
        },
        "state": {
            "description": "State code",
            "type": "string",
            "minLength": "2",
            "maxLength": "2"
        },
        "zip": {
            "description": "Zip code",
            "type": "string",
            "pattern": "^[0-9]{5}(?:-[0-9]{4})?$"
        }
    }
}

If well-indented, the above is moderately readable, if verbose. However, it is preferable to have tools to make it easier to navigate, and also to perform validation. Validation at runtime, of course, depends on the language, but the Python jsonschema library provides an easy means of testing JSON content to make sure the schema does what it's supposed to.

For navigation, there is a great tool called Docson that generates an interactive web page from a JSON schema. Docson is a JavaScript library, so it can dynamically generate the documentation from any JSON schema file it can fetch. Of course, because of cross-origin scripting concerns, there are some limits as to what it can fetch, so the best approach is to grab a local copy rather than serving from a Content Delivery Network (CDN).

With a copy downloaded and running, an example JSON file in the same directory as Docson's index.html, and using Python's SimpleHTTPServer:

$ python -m SimpleHTTPServer 9999

Docson produces a nice looking documentation page:

Image title

JSON Schema Documentation

Opinions expressed by DZone contributors are their own.

Related

  • Exploring JSON Schema for Form Validation in Web Components
  • Datafaker Gen: Leveraging BigQuery Sink on Google Cloud Platform
  • Validate XML Request Against XML Schema in Mule 4
  • Validate JSON Request Against JSON Schema in Mule 4

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!