JSON to JSON Schema Converter

JSON to JSON Schema Converter

Convert complex JSON objects into valid schema structures. Paste your data and get a matching schema in seconds.

JSON to JSON Schema: Generate a First Draft From a Sample

Suppose an API returns a response with forty fields and your tests need to confirm it keeps that shape. Writing the schema by hand means typing every key, type and nesting level, and one typo gives you a schema that quietly checks the wrong thing. A JSON to JSON Schema converter does the first pass for you: you paste a sample object, press Convert, and get a schema that lists each key with its type.

The output is a draft, not a finished contract. It describes the one sample you pasted, and most of the editing you do afterwards comes from the gap between that sample and the real responses your API sends.

How to Use the JSON to JSON Schema Converter

The page has one input box and three buttons: Convert, Sample and Reset.

  1. Paste valid JSON into the input box. Double quotes around keys and strings, no trailing commas and no comments are the usual requirements, and they are also the usual reason a copy from JavaScript code or a config file does not parse. Strip real tokens, email addresses and personal data first. The schema only needs structure, so a placeholder of the same type does the job.
  2. Press Convert. The schema appears as the output.
  3. Copy it into your project. Reset empties the form for the next object, and Sample lets you try the tool before you use your own data.

If the JSON is embedded in a page instead of returned by an API, for example inside a script tag, View the Source Code of Any Web Page helps you find it and copy it out.

JSON to JSON Schema converter on ONE SEO Tools
JSON to JSON Schema converter on ONE SEO Tools

Example: What the Converter Returns for a Small Object

This input has three fields:

{
  "name": "John Doe",
  "age": 30,
  "isEmployed": true
}

And this is the schema that comes back:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Generated schema for Root",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "number" },
    "isEmployed": { "type": "boolean" }
  },
  "required": ["name", "age", "isEmployed"]
}

The $schema line marks the output as draft-07. Each key under properties gets a type taken from the sample value, and required lists all three keys. The value 30 became number, which accepts 30.5 as well, so change it to integer for an ID or a count. The schema also leaves additionalProperties unset, which means an object with an extra key such as nickname still passes. Add "additionalProperties": false if you want unknown keys rejected.

Checking an API Response Against the Schema

Start with the headers. Get HTTP Headers shows what the endpoint sends back, and the Content-Type should be application/json or another JSON media type, such as application/problem+json or application/vnd.api+json. If an HTML error page from a proxy comes back instead, no schema will match it, however it was generated.

Then load the schema into a validator: Ajv for JavaScript or the jsonschema package for Python. The check only protects you when it runs, so put it in your test suite and point it at a few saved responses. If that suite is part of your CI pipeline, a renamed field stops the deploy instead of showing up in production.

Where a One-Sample Schema Breaks Down

Optional fields are the first problem. Every key in your sample ends up in required, but a single object cannot show that a key is present in every response. If the API leaves out middleName for some users, the schema rejects those responses until you remove the key from the list.

Types come from one value too. Say a phone field is a string in your sample and null for users who never added a number. The schema says string, and the first null response fails. Draft-07 accepts a list of types, so "type": ["string", "null"] covers both.

Beyond types, the schema says little. The example output has $schema, title, type, properties and required, and nothing about minimum length, patterns, allowed values or formats such as email and date. Add those rules yourself where they matter.

The output declares draft-07, so check that your validator supports the draft named in the $schema line. Keywords such as required, type lists and additionalProperties are described in the official JSON Schema documentation.


Avatar

Hisham Fouad

CEO / Co-Founder

We build free, practical SEO, webmaster and YouTube tools for website owners and content creators. Have a suggestion? Get in touch through the Contact page.