Generate types and converters from JSON, Schema, and GraphQL
Перейти к файлу
Mark Probst 8be36df298 Don't emit empty "nlohmann" namespace in C++. Fixes #504 2018-02-09 14:35:31 -08:00
.vscode TSLint fixes 2018-01-17 12:53:18 -08:00
appcenter Notify when Homebrew PR sent 2018-01-22 17:58:26 -08:00
doc Templates documentation started 2018-01-15 11:34:25 -08:00
script Fix homebrew release script 2018-01-24 18:44:37 -08:00
src Don't emit empty "nlohmann" namespace in C++. Fixes #504 2018-02-09 14:35:31 -08:00
test Better Markov model 2018-02-08 07:41:25 -08:00
.dockerignore Add codeship files. 2017-12-13 13:43:43 -08:00
.gitignore Scripts for building self-contained binaries 2018-01-30 22:14:21 -08:00
.travis.yml Remove deploy stage from Travis 2018-01-23 10:27:25 -08:00
Dockerfile Update Swift to 4.0.3 2018-01-23 21:38:55 -08:00
LICENSE Create LICENSE 2017-08-30 10:49:31 -07:00
README.md Tighter input/target language display 2018-02-06 11:05:47 -08:00
package-lock.json Lock 2018-01-15 18:18:38 -08:00
package.json Actually use the Markov Chain to infer maps 2018-02-07 19:23:17 -08:00
pkg.sh Scripts for building self-contained binaries 2018-01-30 22:14:21 -08:00
quicktype-logo.svg More appropriate README content for GitHub (#352) 2017-12-21 16:28:54 -08:00
tslint.json Remove comments from tslint.json 2018-02-02 18:58:35 -08:00
yarn.lock Locks 2017-12-03 23:10:06 +07:00

README.md

npm version Build Status Join us in Slack

quicktype generates strongly-typed models and serializers from JSON, JSON Schema, and GraphQL queries, making it a breeze to work with JSON type-safely in any programming language.

Supported Inputs

JSON JSON API URLs JSON Schema GraphQL queries

Target Languages

C# Go C++ Java TypeScript Swift Objective-C Elm JSON Schema

Missing your favorite language? Please implement it!

Installation

There are many ways to use quicktype. app.quicktype.io is the most powerful & complete UI. The web app also works offline and doesn't send your sample data over the Internet, so paste away!

For the best CLI, we recommend installing quicktype globally via npm:

npm install -g quicktype

Other options:

* limited functionality

Using quicktype

# Run quicktype without arguments for help and options
quicktype

# quicktype a simple JSON object in C#
echo '{ "name": "David" }' | quicktype -l csharp

# quicktype a top-level array and save as Go source
echo '[1, 2, 3]' | quicktype -o ints.go

# quicktype a sample JSON file in Swift
quicktype person.json -o Person.swift

# A verbose way to do the same thing
quicktype \
  --src person.json \
  --src-lang json \
  --lang swift \
  --top-level Person \
  --out Person.swift

# quicktype a directory of samples as a C++ program
# Suppose ./blockchain is a directory with files:
#   latest-block.json transactions.json marketcap.json
quicktype ./blockchain -o blockchain-api.cpp

# quicktype a live JSON API as a Java program
quicktype https://api.somewhere.com/data -o Data.java

The recommended way to use quicktype is to generate a JSON schema from sample data, review and edit the schema, commit the schema to your project repo, then generate code from the schema as part of your build process:

# First, infer a JSON schema from a sample.
quicktype pokedex.json -o schema.json

# Review the schema, make changes,
# and commit it to your project repo.

# Finally, generate model code from schema in your
# build process for whatever languages you need:
quicktype -s schema schema.json -o src/ios/models.swift
quicktype -s schema schema.json -o src/android/Models.java
quicktype -s schema schema.json -o src/nodejs/Models.ts

# All of these models will serialize to and from the same
# JSON, so different programs in your stack can communicate
# seamlessly.

Development

quicktype is open source so if you'd like additional options or a new target language, you can build it yourself and send a pull request. quicktype is implemented in TypeScript and requires nodejs and npm to build and run.

Setup, Build, Run

Clone this repo and do:

npm install
script/quicktype # rebuild (slow) and run (fast)

Edit

Install Visual Studio Code, open this workspace, and install the recommended extensions:

code . # opens in VS Code

Live-reloading for quick feedback

When working on an output language, you'll want to view generated output as you edit. Use npm start to watch for changes and recompile and rerun quicktype for live feedback. For example, if you're developing a new renderer for fortran, you could use the following command to rebuild and reinvoke quicktype as you implement your renderer:

npm start -- "--lang fortran pokedex.json"

The command in quotes is passed to quicktype, so you can render local .json files, URLs, or add other options.

Test

quicktype has many complex test dependencies:

  • dotnetcore SDK
  • Java, Maven
  • elm tools
  • g++ C++ compiler
  • golang stack
  • swift compiler
  • clang and Objective-C Foundation (must be tested separately on macOS)

We've assembled all of these tools in a Docker container that you build and test within:

# Build and attach to Docker container
script/dev

# Run full test suite
npm run test

# Test a specific language (see test/languages.ts)
FIXTURE=golang npm test

# Test a single sample or directory
FIXTURE=swift npm test -- pokedex.json
FIXTURE=swift npm test -- test/inputs/json/samples