Json Typedef Infer

A CLI tool that generates JSON Typedef schemas from example data
Alternatives To Json Typedef Infer
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
React Jsonschema Form12,7115662814 hours ago103December 16, 2019284apache-2.0TypeScript
A React component for building Web forms from JSON Schema.
Ajv12,513801,6067,9857 days ago349March 22, 2022275mitTypeScript
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Quicktype10,022429019 hours ago674September 12, 2022404apache-2.0TypeScript
Generate types and converters from JSON, Schema, and GraphQL
Jsonschema2pojo5,9801153413 days ago52May 03, 2022175apache-2.0Java
Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
Json Editor5,376141375 years ago19August 07, 2016461mitJavaScript
JSON Schema Based Editor
Resume Cli4,29393343 months ago106April 20, 202298mitJavaScript
CLI tool to easily setup a new resume 📑
Jsonschema4,15415,5302,4244 hours ago74July 07, 202227mitPython
An implementation of the JSON Schema specification for Python
Mimesis3,97242197 days ago37June 22, 20228mitPython
Mimesis is a robust data generator for Python, capable of rapidly producing large volumes of synthetic data for various use cases.
Json Schema3,3968,5014892 months ago46April 13, 202295mitPHP
PHP implementation of JSON schema. Fork of the http://jsonschemaphpv.sourceforge.net/ project
Fast Json Stringify3,186747135a month ago136September 26, 202213mitJavaScript
2x faster than JSON.stringify()
Alternatives To Json Typedef Infer
Select To Compare

Alternative Project Comparisons

jtd-infer: Generate JSON Typedef schemas from examples Crates.io Docs.rs

JSON Type Definition, aka RFC8927, is an easy-to-learn, standardized way to define a schema for JSON data. You can use JSON Typedef to portably validate data across programming languages, create dummy data, generate code, and more.

jtd-infer is a tool that generates ("infers") a JSON Typedef schema from example data.

echo '{ "name": "Joe", "age": 42 }' | jtd-infer | jq
  "properties": {
    "age": {
      "type": "uint8"
    "name": {
      "type": "string"


On macOS, you can install jtd-infer via Homebrew:

brew install jsontypedef/jsontypedef/jtd-infer

For all other platforms, you can download and extract the binary yourself from the latest release. You can also install using cargo by running:

cargo install jtd_infer


For high-level guidance on how to use jtd-infer, see "Inferring a JSON Typedef Schema from Real Data" in the JSON Typedef website docs.

Basic Usage

To invoke jtd-infer, you can either:

  1. Have it read from STDIN. This is the default behavior.
  2. Have it read from a file. To do this, pass a file name as the last argument to jtd-infer.

jtd-infer reads a sequence of JSON messages. So for example, if you have a file like this in data.json:

{ "name": "john doe", "age": 42 }
{ "name": "jane doe", "age": 45 }

You can give it to jtd-infer in two ways:

# Both of these do the same thing.
cat data.json | jtd-infer
jtd-infer data.json

In both cases, you'd get this output:


Changing the default number type

⚠️ This section is often important if you are retrofitting JSON Typedef to a JavaScript-based application.

By default, JSON Typedef will infer the most specific possible type for inputs. So, for example, it will guess uint8 if it sees a 12 in your input:

echo "12" | jtd-infer

However, if you're giving JSON Typedef a small sample set, or if you in practice have data that is far smaller than the actual numerical datatypes your application supports, then this behavior may be undesirable. For example, it's common for JavaScript-based applications to actually support float64 for all numeric inputs, because JavaScript numbers are IEEE double-precision floats.

To tell JSON Typedef to prefer a different type than the one it would normally guess, you can use --default-number-type to change its behavior. For example:

# JavaScript numbers are all float64s, and so it's pretty common for JavaScript
# applications to not check if inputs are integers or within a particular range.
# If you don't want to make your JSON Typedef schema strict about decimal,
# negative, or out of int range numbers, you can pass float64 as the default
# number type.
echo "12" | jtd-infer --default-number-type=float64

Another use-case is if you're writing an application that uses signed 32-bit ints everywhere, and your example data simply never in practice has examples of negative numbers or numbers too big for 8- or 16-bit numbers. You can achieve that by using int32 as your default number type:

echo "12" | jtd-infer --default-number-type=int32

Note that jtd-infer will ignore your default if it doesn't match with the data. For example, int32 only works with whole numbers, so if a decimal number or a number too big for 32-bit signed integers comes in, it will fall back to float64:

# both of these output {"type":"float64"}
echo "3.14" | jtd-infer --default-number-type=int32
echo "9999999999" | jtd-infer --default-number-type=int32

Advanced Usage: Providing Hints

By default, jtd-infer will never output enum, values, or discriminator schemas. This is by design: by always being consistent with what it outputs, jtd-infer is more predictable and reliable.

If you want jtd-infer to output an enum, values, or discriminator, you can use the --enum-hint, --values-hint, and --discriminator-hint flags. You can pass each of these flags multiple times.

All of the hint flags accept JSON Pointers as values. If you're used to the JavaScript-y syntax of referring to things as $.foo.bar, the equivalent JSON Pointer is /foo/bar. jtd-infer treats - as a "wildcard". /foo/-/bar is equivalent to the JavaScript-y $.foo.*.bar.

As a corner-case, if you want to point to the root / top-level of your input, then use the empty string as the path. See "Using --values-hint" for an example of this.

Using --enum-hint

By default, strings are always inferred to be { "type": "string" }:

echo '["foo", "bar", "baz"]' | jtd-infer

But you can instead have jtd-infer output an enum by providing a path to the string you consider to be an enum. In this case, it's any element of the root of the array -- the JSON Pointer for that is /-:

echo '["foo", "bar", "baz"]' | jtd-infer --enum-hint=/-

Using --values-hint

By default, objects are always assumed to be "structs", and jtd-infer will generate properties / optionalProperties. For example:

echo '{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, 9]}' | jtd-infer

If your data is more like a map / dictionary, pass a values-hint that points to the object that you want a values schema from. In this case, that's the root-level object, which in JSON Pointer is just an empty string:

echo '{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, 9]}' | jtd-infer --values-hint=

Using --discriminator-hint

By default, objects are always assumed to be "structs", and jtd-infer will generate properties / optionalProperties. For example:

echo '[{"type": "s", "value": "foo"},{"type": "n", "value": 3.14}]' | jtd-infer

If your data has a special "type" property that tells you what's in the rest of the object, then use --discriminator-hint to point to that property. jtd-infer will output an appropriate discriminator schema instead:

echo '[{"type": "s", "value": "foo"},{"type": "n", "value": 3.14}]' | jtd-infer --discriminator-hint=/-/type | jq
  "elements": {
    "discriminator": "type",
    "mapping": {
      "s": {
        "properties": {
          "value": {
            "type": "string"
      "n": {
        "properties": {
          "value": {
            "type": "float64"
Popular Schema Projects
Popular Json Projects
Popular Data Formats Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Json Pointer