All Projects → quicktype → Quicktype

quicktype / Quicktype

Licence: apache-2.0
Generate types and converters from JSON, Schema, and GraphQL

Programming Languages

typescript
32286 projects
python
139335 projects - #7 most used programming language
shell
77523 projects
javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects
powershell
5483 projects

Projects that are alternatives of or similar to Quicktype

Json Schema Validator
A fast Java JSON schema validator that supports draft V4, V6, V7 and V2019-09
Stars: ✭ 292 (-96.09%)
Mutual labels:  json-schema, json
Vue Json Ui Editor
Edit JSON in UI form with JSON Schema and Vue.js
Stars: ✭ 392 (-94.74%)
Mutual labels:  json-schema, json
Pyjfuzz
PyJFuzz - Python JSON Fuzzer
Stars: ✭ 342 (-95.41%)
Mutual labels:  json-schema, json
Rxdb
🔄 A client side, offline-first, reactive database for JavaScript Applications
Stars: ✭ 16,670 (+123.49%)
Mutual labels:  graphql, json-schema
Full Stack Fastapi Postgresql
Full stack, modern web application generator. Using FastAPI, PostgreSQL as database, Docker, automatic HTTPS and more.
Stars: ✭ 7,635 (+2.36%)
Mutual labels:  json-schema, json
Json Schema To Ts
Infer TS types from JSON schemas 📝
Stars: ✭ 261 (-96.5%)
Mutual labels:  json-schema, json
Json
C++ header-only JSON library
Stars: ✭ 343 (-95.4%)
Mutual labels:  json-schema, json
Json Serverless
Transform a JSON file into a serverless REST API in AWS cloud
Stars: ✭ 108 (-98.55%)
Mutual labels:  graphql, json
Json Forms
JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
Stars: ✭ 549 (-92.64%)
Mutual labels:  json-schema, json
Jsonforms
Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
Stars: ✭ 542 (-92.73%)
Mutual labels:  json-schema, json
Autoserver
Create a full-featured REST/GraphQL API from a configuration file
Stars: ✭ 188 (-97.48%)
Mutual labels:  graphql, json
Jsonschema2pojo
Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
Stars: ✭ 5,633 (-24.48%)
Mutual labels:  json-schema, json
Json To Simple Graphql Schema
Transforms JSON input into a GraphQL schema
Stars: ✭ 185 (-97.52%)
Mutual labels:  graphql, json
Dotnet Fake Json Server
Fake JSON Server is a Fake REST API that can be used as a Back End for prototyping or as a template for a CRUD Back End.
Stars: ✭ 265 (-96.45%)
Mutual labels:  graphql, json
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (-98.18%)
Mutual labels:  graphql, json
Jseg
A super simple, in-memory, JS graph database.
Stars: ✭ 344 (-95.39%)
Mutual labels:  graphql, json
Prettier
Prettier is an opinionated code formatter.
Stars: ✭ 41,411 (+455.18%)
Mutual labels:  graphql, json
Persianjsonplaceholder
Persian fake REST/GraphQL API for testing and prototyping.
Stars: ✭ 110 (-98.53%)
Mutual labels:  graphql, json
Plank
A tool for generating immutable model objects
Stars: ✭ 449 (-93.98%)
Mutual labels:  json-schema, json
Stash
An organizer for your porn, written in Go
Stars: ✭ 591 (-92.08%)
Mutual labels:  graphql, json

npm version Build status Join us in Slack

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

Supported Inputs

JSON JSON API URLs JSON Schema
TypeScript GraphQL queries

Target Languages

Ruby JavaScript Flow Rust Kotlin
Dart Python C# Go C++
Java TypeScript Swift Objective-C Elm
JSON Schema Pike Prop-Types Haskell

Missing your favorite language? Please implement it!

Installation

There are many ways to use quicktype. app.quicktype.io is the most powerful and 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

Generating code from JSON schema

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 -l schema -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.

Generating code from TypeScript (Experimental)

You can achieve a similar result by writing or generating a TypeScript file, then quicktyping it. TypeScript is a typed superset of JavaScript with simple, succinct syntax for defining types:

interface Person {
  name: string;
  nickname?: string; // an optional property
  luckyNumber: number;
}

You can use TypeScript just like JSON schema was used in the last example:

# First, infer a TypeScript file from a sample (or just write one!)
quicktype pokedex.json -o pokedex.ts --just-types
# Review the TypeScript, make changes, etc.
quicktype pokedex.ts -o src/ios/models.swift

Calling quicktype from JavaScript

You can use quicktype as a JavaScript function within node or browsers. First add the quicktype-core package:

$ npm install quicktype-core

In general, first you create an InputData value with one or more JSON samples, JSON schemas, TypeScript sources, or other supported input types. Then you call quicktype, passing that InputData value and any options you want.

const {
  quicktype,
  InputData,
  jsonInputForTargetLanguage,
  JSONSchemaInput,
  FetchingJSONSchemaStore,
} = require("quicktype-core");

async function quicktypeJSON(targetLanguage, typeName, jsonString) {
  const jsonInput = jsonInputForTargetLanguage(targetLanguage);

  // We could add multiple samples for the same desired
  // type, or many sources for other types. Here we're
  // just making one type from one piece of sample JSON.
  await jsonInput.addSource({
    name: typeName,
    samples: [jsonString],
  });

  const inputData = new InputData();
  inputData.addInput(jsonInput);

  return await quicktype({
    inputData,
    lang: targetLanguage,
  });
}

async function quicktypeJSONSchema(targetLanguage, typeName, jsonSchemaString) {
  const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());

  // We could add multiple schemas for multiple types,
  // but here we're just making one type from JSON schema.
  await schemaInput.addSource({ name: typeName, schema: jsonSchemaString });

  const inputData = new InputData();
  inputData.addInput(schemaInput);

  return await quicktype({
    inputData,
    lang: targetLanguage,
  });
}

async function main() {
  const { lines: swiftPerson } = await quicktypeJSON(
    "swift",
    "Person",
    jsonString
  );
  console.log(swiftPerson.join("\n"));

  const { lines: pythonPerson } = await quicktypeJSONSchema(
    "python",
    "Person",
    jsonSchemaString
  );
  console.log(pythonPerson.join("\n"));
}

main();

The argument to quicktype is a complex object with many optional properties. Explore its definition to understand what options are allowed.

Contributing

quicktype is Open Source and we love contributors! In fact, we have a list of issues that are low-priority for us, but for which we'd happily accept contributions. Support for new target languages is also strongly desired. If you'd like to contribute, need help with anything at all, or would just like to talk things over, come join us on Slack.

Setup, Build, Run

quicktype is implemented in TypeScript and requires nodejs and npm to build and run.

First, install typescript globally via npm:

Clone this repo and do:

macOS / Linux

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

Windows

npm install --ignore-scripts # Install dependencies
npm install -g typescript # Install typescript globally
tsc --project src/cli # Rebuild
node dist\cli\index.js # Run

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:

  • crystal compiler
  • dotnetcore SDK
  • Java, Maven
  • elm tools
  • g++ C++ compiler
  • golang stack
  • swift compiler
  • clang and Objective-C Foundation (must be tested separately on macOS)
  • rust tools
  • pike interpreter
  • Bundler for Ruby
  • haskell stack

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].