Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@adobe/jsonschema2md

adobe42.1kApache-2.08.0.2TypeScript support: included

Validate and document complex JSON Schemas the easy way.

readme

JSON Schema Markdown Tools

GitHub Actions

Documenting and validating complex JSON Schemas can be hard. This tool makes it easier by providing a number of scripts that can turn JSON Schema files into readable Markdown documentation that is ready for consumption on GitHub or processed using Jekyll or other static site generators.

These tools have been introduced by Adobe to document Adobe's Experience Data Models (XDM), but can be used for other JSON Schema documents, too.

JSON Schema Support

jsonschema2md is developed against JSON Schema 2019-09, but not the full vocabulary is supported. Please check the detailed list of JSON Schema keywords supported by jsonschema2md. This list is updated by our tests.

Requirements

  • npm version 3.10.8 or up
  • node v18 or v20 or up

Example Output

Using the schemas in examples/schemas (note the *.schema.json extension), the output in examples/docs has been generated.

Installing and running

$ npm install -g @adobe/jsonschema2md

# show usage information
$ jsonschema2md

# run task
$ jsonschema2md -d examples/schemas -o examples/docs
# generated output for whole folder is written to ./examples/docs

By default, jsonschema2md looks for schema files ending in *.schema.json. You can specify another extension by using the --schema-extension or -e command line argument.

Internationalization

The generated documentation can be internationalized. Select the language you want to use for the output using the -l parameter.

Supported languages are:

  • English
  • German

If you want to provide a translation of your own, please use GitLocalize

Display custom attributes in the property description

jsonschema2md displays only the attributes of an property which are defined by the JSON Schema standard. If you want to display additional attributes in the property description you could provide these with the --properties (or -p) parameter.

# include both the `version` and the `test` attribute
$ jsonschema2md -d examples/schemas -o examples/docs -p version -p test

Disable header template

In some cases you do not need a header because it does not provide any useful information. With the --header (or -h) parameter you can disable the inclusion of headers.

# run against JSON Schema Draft 06
$ jsonschema2md -d examples/schemas -o examples/docs -v 06 -h false

Examples as YAML

If you are using JSON Schema to validate YAML documents, for instance configuration files, you might wish for examples to be formatted as YAML, not JSON. Using the command line option -f yaml or --example-format yaml achieves this goal.

Using JSON Schema Markdown Tools from npm

You can conveniently use the JSON Schema Markdown Tools from npm. This makes it possible to set up a conversion toolchain for your JSON Schema project that is driven entirely by npm. To do so, first define the dependency by adding this to your "devDependencies" section of package.json

  "devDependencies": {
    "@adobe/jsonschema2md": "^6.0.0"
  }

With script

Then add the following to the "scripts" section of your package.json and adapt accordingly:

"scripts": {
  "prepare": "mkdir -p docs/reference && jsonschema2md -o docs/reference -d schemas/draft-04"
}

If you run npm install before running npm run prepare, npm will install the @adobe/jsonschema2md in a node_modules/.bin path, even if you did not install the JSON Schema Markdown beforehand.

With API for Node.js

const {jsonschema2md} = require('@adobe/jsonschema2md');
const schema = require('examples/schemas/example.schema.json');

const markdown = jsonschema2md(schema, {
  includeReadme: true,
});
`

Tests

Ensure you have all the dependencies installed via npm install, then run:

npm test

This will run our Jasmine test suite as well as lint the JavaScript according to our style guide (see below).

CI

Continuous integration runs on Github Actions. All pull requests automatically trigger a job that runs the tests by executing the main.yml.

Code Coverage

npm run test will generate a code coverage report at the end of the test run. Anything below 100% coverage counts as a test failure.

Style Guide / Linting

This project uses eslint to enforce JavaScript coding style. To run the linter:

npm run lint

TODOs

Add support for missing keywords

Contributing

Please see Contributing.md for details. Pull requests are welcome.

Copyright 2017 Adobe Systems Incorporated. All rights reserved. This file is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

changelog

8.0.2 (2024-04-09)

Bug Fixes

8.0.1 (2024-03-25)

Bug Fixes

  • deps: update external dependencies (51be972)

8.0.0 (2024-03-25)

Build System

BREAKING CHANGES

  • requires node 18

7.1.6 (2024-03-25)

Bug Fixes

  • deps: update dependency @adobe/helix-log to v6.0.1 (b54415a)
  • deps: update external fixes (f515169)
  • deps: update external fixes (e23d8f0)
  • deps: update external major (#516) (d7d72e6)

7.1.5 (2022-12-12)

Bug Fixes

  • fix typo in 'any of the following' text (d7039b9)

7.1.4 (2022-11-29)

Bug Fixes

  • deps: update dependency fs-extra to v11 (291515e)

7.1.3 (2022-11-14)

Bug Fixes

  • markdown-builder: guard against enum being not an array (aa46ac4), closes #458

7.1.2 (2022-10-06)

Bug Fixes

7.1.1 (2022-05-19)

Bug Fixes

  • i18n: align Dutch locale name with standard pattern (d940cd4), closes #426
  • i18n: dutch locale available as command line option (e8c9304), closes #426
  • i18n: support Dutch locale as command line option (0c0fbbd)

7.1.0 (2022-05-19)

Features

7.0.1 (2022-05-19)

Bug Fixes

  • deps: update dependency fs-extra to v10.1.0 (#417) (ba2e2e5)
  • package: bump minimum node version to 14 (f26283e)

7.0.0 (2022-02-14)

Bug Fixes

  • deps: update dependency @adobe/helix-log to v6 (#363) (6298ed2)
  • index: remove reference to single input file (7324427), closes #386
  • symbols: tweak exports (d31ab23)
  • tests: use fileToURLPath for dirname (352d032)

Code Refactoring

Features

  • api: change shape of input and output data (797090f)
  • api: create typescript declaration for api (92426f9)

BREAKING CHANGES

  • jsonschema2md now uses ECMAScript Modules (import/export) instead of CommonJS Modules (require/exports). This was driven by the desire to stay up to date with dependencies that switched to ESM.

6.1.4 (2021-09-20)

Bug Fixes

  • deps: update dependency @adobe/helix-log to v5.0.5 (#349) (fbe1d49)

6.1.3 (2021-09-02)

Bug Fixes

  • deps: update dependency @adobe/helix-log to v5.0.4 (ba86b48)

6.1.2 (2021-09-02)

Bug Fixes

  • readmebuilder: reference twice for objects (0bc9e68)

6.1.1 (2021-08-12)

Bug Fixes

  • markdownbuilder: guard against empty definitions object (f1b90c2), closes #334

6.1.0 (2021-07-08)

Bug Fixes

  • i18n: avoid passing non-string parameters to i18n engine (abec736)

Features

6.0.3 (2021-05-04)

Bug Fixes

6.0.2 (2021-04-17)

Bug Fixes

  • deps: update external fixes (32bcef6)

6.0.1 (2021-04-12)

Bug Fixes

  • deps: update dependency @adobe/helix-log to v5.0.3 (#299) (b3bc372)

6.0.0 (2021-04-04)

Bug Fixes

  • lib/traverseschema.js: filter out skippable keywords based on parent's type (0f75837), closes #282

BREAKING CHANGES

  • lib/traverseschema.js: If schema contained 'properties', 'required' or 'examples' as a part of JSON schema (i.e. it was described as 'properties' within an object of 'object' type), these will be included into output.

5.0.7 (2021-04-02)

Bug Fixes

  • deps: update dependency @adobe/helix-log to v5.0.2 (040a495)

5.0.6 (2021-04-02)

Bug Fixes

  • deps: update dependency @adobe/helix-log to v5.0.1 (0017876)

5.0.5 (2021-03-20)

Bug Fixes

  • deps: update dependency readdirp to v3.6.0 (47a37dc)

5.0.4 (2021-03-06)

Bug Fixes

  • deps: update external fixes (d409140)

5.0.3 (2021-02-25)

Bug Fixes

  • deps: update dependency @adobe/helix-log to v5 (#285) (ca21fe4)

5.0.2 (2021-01-30)

Bug Fixes

  • lib/markdownBuilder.js: use simpletitle for makeproperties (d2100c6)

5.0.1 (2021-01-25)

Bug Fixes

  • deps: update external fixes (48ed197)

5.0.0 (2021-01-21)

Bug Fixes

  • deps: bump semantic-release versions (44cc702)
  • deps: npm audit fix (24a577e)
  • deps: update dependency @adobe/helix-log to v4.5.3 (19f7ab4)
  • deps: update dependency js-yaml to v4 (2dbca6f)
  • schemaproxy.js: fix resolving $refs that are file references (c6adf01), closes #92
  • traverseschema.js: skip generating files for certain keywords in the schema (fc50969)

BREAKING CHANGES

  • traverseschema.js: The extranious files, if they have some other value, will not be generated and there is no mechanism to continue to g

4.2.2 (2021-01-21)

Bug Fixes

  • deps: bump semantic-release versions (44cc702)
  • deps: npm audit fix (24a577e)
  • deps: update dependency @adobe/helix-log to v4.5.3 (19f7ab4)
  • deps: update dependency js-yaml to v4 (2dbca6f)
  • schemaproxy.js: fix resolving $refs that are file references (c6adf01), closes #92

4.2.2 (2021-01-02)

Bug Fixes

  • deps: bump semantic-release versions (44cc702)
  • deps: npm audit fix (24a577e)
  • deps: update dependency @adobe/helix-log to v4.5.3 (19f7ab4)
  • schemaproxy.js: fix resolving $refs that are file references (c6adf01), closes #92

4.2.2 (2020-12-19)

Bug Fixes

  • deps: bump semantic-release versions (44cc702)
  • deps: npm audit fix (24a577e)
  • deps: update dependency @adobe/helix-log to v4.5.3 (19f7ab4)
  • schemaproxy.js: fix resolving $refs that are file references (c6adf01), closes #92

4.2.2 (2020-12-15)

Bug Fixes

  • deps: bump semantic-release versions (44cc702)
  • deps: npm audit fix (24a577e)
  • deps: update dependency @adobe/helix-log to v4.5.3 (19f7ab4)
  • schemaproxy.js: fix resolving $refs that are file references (c6adf01), closes #92

4.2.2 (2020-12-15)

Bug Fixes

  • deps: bump semantic-release versions (44cc702)
  • deps: npm audit fix (24a577e)
  • schemaproxy.js: fix resolving $refs that are file references (c6adf01), closes #92

4.2.2 (2020-12-15)

Bug Fixes

  • deps: bump semantic-release versions (44cc702)
  • deps: npm audit fix (24a577e)
  • schemaproxy.js: fix resolving $refs that are file references (c6adf01), closes #92

4.2.2 (2020-12-14)

Bug Fixes

  • deps: bump semantic-release versions (44cc702)
  • deps: npm audit fix (24a577e)
  • schemaproxy.js: fix resolving $refs that are file references (c6adf01), closes #92

4.2.1 (2020-10-21)

Bug Fixes

  • lib/markdownbuilder.js: propTable property anchor link generated with github-slugger (9883b8f)

4.2.0 (2020-09-01)

Features

  • markdownbuilder: create an option to skip any property in markdown #243 (56b7a2f)

4.1.6 (2020-07-31)

Bug Fixes

  • markdown: correcly show type of nullable types in header (53c1a0b), closes #237

4.1.5 (2020-06-22)

Bug Fixes

  • deps: npm audit fix (2be8a58)
  • markdown: avoid ambiguities around property names (a4543c4), closes #232

4.1.4 (2020-06-22)

Bug Fixes

  • definition object defintions based on proplist structure (2fb9fc5), closes #228

4.1.3 (2020-06-04)

Bug Fixes

  • moved definitions to bottom of output file (1b27fff), closes #226

4.1.2 (2020-04-23)

Bug Fixes

  • lib/index.js: made -h/--header a boolean arg (5ba2719), closes #209

4.1.1 (2020-04-14)

Bug Fixes

  • deps: npm audit fix (b13ab35)
  • enum: fix doc generation for enums that contain arrays (667a106), closes #219

4.1.0 (2020-03-05)

Features

  • examples: enable examples to be formatted in YAML using command line option -f yaml (01119ba)

4.0.13 (2020-01-31)

Bug Fixes

  • i18n: update German translations (8cf38e4)

4.0.12 (2020-01-30)

Bug Fixes

  • dont use backslash for URLs on windows (5149522), closes #211

4.0.11 (2020-01-26)

Bug Fixes

  • package: fix & clean up dependencies (890e86d), closes #210

4.0.10 (2020-01-21)

Bug Fixes

  • deps: pin es2015-i18n-tag version (c531b50), closes #207

4.0.9 (2020-01-20)

Bug Fixes

  • markdown: prevent unescaped objects in markdown AST (87d709a), closes #201

4.0.8 (2020-01-15)

Bug Fixes

  • index.js: -x flag is not working properly for the suppression case (d929d9b)

4.0.7 (2020-01-14)

Bug Fixes

  • markdown: increase robustness when using format as a property name (cda0bec), closes #198

4.0.6 (2020-01-14)

Bug Fixes

  • markdown: catch error when using title as a property name (b4b8855)

4.0.5 (2020-01-14)

Bug Fixes

  • slugger: fix slugger crash due to title property (4f0ab31), closes #196

4.0.4 (2020-01-14)

Bug Fixes

  • cli: do not exit after creating readme.md (cb7d012)
  • cli: make the -n or --no-readme option work again (3c63c03)
  • loader: guard against endless wrapping (dd1f7f6), closes #194

4.0.3 (2020-01-09)

Bug Fixes

  • schema: do not recurse endlessly when writing cyclic schemas (297f0d5), closes #185

4.0.2 (2019-12-20)

Bug Fixes

  • cli: fix traverse function when called from CLI (f211375)

4.0.1 (2019-12-20)

Bug Fixes

  • titles: more robust handling of title generation for untitled schemas (c546a28), closes #185
  • traversal: fix endless loop in schema traversal (af85c59), closes #185

4.0.0 (2019-12-16)

Bug Fixes

  • i18n: use correct file name format (43a74f4)
  • markdown: constraint values can be zero now (2e057fd)
  • markdown: handle null as a constant value (e652e11)
  • proxy: remove logging statements (616a1d9)
  • schemas: remove references going nowhere (2186142)

Build System

  • dependencies: remove unused dependencies (dbc9192)

Code Refactoring

  • cli: remove bluebird, lodash, simplify arg parsing (b6b1822)

Continuous Integration

Documentation

Features

  • cli: generate JSON schema output (dd18f3b), closes #176
  • formats: add support for formats: json-pointer, relative-json-pointer, regex, and uri-template (689c158)
  • i18n: new internationalization system (1a664de)
  • i18n: provide complete en_US translation (5eb0c89)
  • markdown: add header surpression (6225b9f)
  • markdown: add support for default keyword (72a0fde)
  • markdown: add support for comments (07bb52f)
  • markdown: add YAML frontmatter support (4df92e6)
  • markdown: create and write markdown (e521541)
  • markdown: generate additional detail (cc07df2)
  • markdown: generate header again (011427c)
  • markdown: generate some property details (fa34cf1)
  • markdown: generate type details (c9f19e1)
  • markdown: highlight keyword usage for documentation (d35e4ed), closes #100
  • markdown: list nested schemas in README (608674b)
  • markdown: list nested schemas in README (87e8489)
  • markdown: show examples (c8e8dfa)
  • markdown: show extensibility and abstraction in header (90a9a8e)
  • markdown: show id and status in header (08e1923)
  • markdown: show id and status in header (b6fcf53)
  • markdown: show join types (12af018)
  • markdown: show some info about properties, switch i18n library (f8a32df)
  • markdown: show type, link, additional and custom properties in header (eff129a)
  • markdown: show value constraints (515969c)
  • markdown: support item arrays and additionalItems (c9fbcdf), closes #31
  • markdown: support patternProperties and additionalProperties (1386ee3), closes #95 #180
  • proxy: generate meta information (ac65ac6)
  • proxy: generate slugs (eacbf38)
  • proxy: resolve references (4cea068)
  • readme: generate readme again (d6b9e5e)
  • readme: mention the most common schema version (fc583d7)
  • schema: add full support for "A Vocabulary for the Contents of String-Encoded Data" (96ca3a6)
  • schema: add support for keyword $defs (70b63c8)
  • schema: add support for keyword deprecated (934b856)
  • schema: add support for readOnly and writeOnly schemas and properties (7452882)

BREAKING CHANGES

  • changelog:
  • i18n: The file format for the i18n files has changed

You can now specify the language to use using -l and jsonschema2md will pick up the correct language configuration.

  • test: Node 8 is no longer supported
  • dependencies: Removes the JSON schema validation feature entirely
  • cli: Repaces lodash with ferrum, removed bluebird, changes the meaning of --schema-out or -x to be no longer relative to output dir

The --schema-out or -x command line option is no longer relative to the output path (specified with -o or --out)


Note about Version 4.0

jsonschema2md v4.0.0 has been a major rewrite that changes output format, command line parameters, i18n templates in order to increase the coverage of the JSON Schema specification and to make the project more maintainable.

The JSON Schema validation functionality has been dropped entirely, as it is easier to just use ajv for that directly.


3.3.1 (2019-09-18)

Bug Fixes

  • package: update @adobe/helix-log to version 2.0.0 (33792f6)

3.3.0 (2019-08-26)

Features

  • allow display of custom attributes in the property description (0634309), closes #151

3.2.0 (2019-08-20)

Features

3.1.2 (2019-08-07)

Bug Fixes

  • always output POSIX paths (3c1c42c)
  • fix error logging from submodules (dc634b2)

3.1.1 (2019-07-31)

Bug Fixes

  • i18n init: moved the i18n init part to the cli.js (5e37d2d), closes #157
  • markdownwriter.js: use path function to resolve the path (5fe7db2), closes #157

3.1.0 (2019-07-30)

Features

  • i18n: enable localization of all strings, provide en as default language (daa58a2), closes #143

3.0.1 (2019-07-29)

Bug Fixes

  • schema.js: fix $ref not being resolved when nested deeper than once within an object (6eb73c3), closes #155

3.0.0 (2019-07-24)

Bug Fixes

  • cli: fix breaking changes to readdirp API (5150f3f)
  • package: update readdirp to version 3.1.1 (05cd51e), closes #127

Build System

  • package: require minimum node version: 8 (a9ec935)

BREAKING CHANGES

  • package: Node 7 and lower are no longer supported, Node 8 is now the minimum version

2.1.2 (2019-07-19)

Bug Fixes

  • Fix $ref within nested objects not generating correct markdown (b8c9a49), closes #136

2.1.1 (2019-05-29)

Bug Fixes

  • package: update async to version 3.0.1 (4ffa21e)

2.1.0 (2019-04-30)

Features

  • Apply prettier to generated markdown files for improved formatting (0e8bde4)

2.0.0 (2019-03-26)

Bug Fixes

BREAKING CHANGES

  • release: Major version bump

1.0.0 (2019-03-18)

Bug Fixes

  • ci: use node8 for releases (9c2a186)