jsl-codegen
generates data structures from JSON Schema Language. Define your
schema in a portable way with JSL, and then generate idiomatic code -- structs,
classes, interfaces, et cetera -- for any language.
jsl-codegen
can output code for the following languages:
- TypeScript
- Golang
- Java
More targets can be added relatively easily. Just open a GitHub issue on this project to make a feature request!
As a quick example, here's how you create some TypeScript from a JSL schema:
jsl-codegen --ts-out=gen/typescript -- user.json
That will output some TypeScript into gen/typescript/user.ts
.
If you're using TypeScript, jsl-codegen
can convert a JSL schema like this:
{
"properties": {
"name": { "type": "string" },
"isAdmin": { "type": "boolean" }
},
"optionalProperties": {
"favoriteNumbers": { "elements": { "type": "number" }}
}
}
Into this:
interface User {
name: string;
isAdmin: boolean;
favoriteNumbers?: number[];
}
But using the same exact schema, you can also generate some Java:
public class User {
public String name;
public boolean isAdmin;
public List<Double> favoriteNumbers;
}
Or some Golang:
type User struct {
Name string `json:"name"`
IsAdmin bool `json:"isAdmin"`
FavoriteNumber []float64 `json:"favoriteNumbers"`
}
JSL supports multiple output languages, and can output multiple languages at once. As a consequence, all of the following parameters can be provided simultaneously.
jsl-codegen 1.0
Generates code from a JSON Schema Language schema
USAGE:
jsl-codegen [OPTIONS] [--] <INPUT>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--go-out <go-out> Go output directory
--java-out <java-out> Java output directory
--java-pkg <java-pkg> Java output package
--ts-out <ts-out> TypeScript output directory
ARGS:
<INPUT> Input JSON Schema Language schema file