as command (jsonknife)

Handling JSON data espencially swagger like structure.

  • bundle
  • cut
  • deref
  • examples

deref and cut

$ tree src
src
└── colors.yaml

src/colors.yaml

deref

deref is unwrap function.

mkdir -p dst
jsonknife deref --src src/colors.yaml --ref "#/rainbow/yellow" > dst/00dref.yaml
jsonknife deref --src src/colors.yaml --ref "#/rainbow/yellow@yellow" > dst/01dref.yaml
jsonknife deref --src src/colors.yaml --ref "#/rainbow/yellow@yellow" --ref "#/rainbow/indigo@indigo" > dst/02dref.yaml

dst/00deref.yaml with –ref “#/rainbow/yellow”

dst/01deref.yaml with –ref “#/rainbow/yellow@yellow”

dst/02deref.yaml with –ref “#/rainbow/yellow@yellow” –ref “#/rainbow/indigo@indigo”

cut

$ jsonknife cut --src ./dst/02deref.yaml --ref "#/yellow" > ./dst/00cut.yaml

dst/00cut.yaml

bundle and deref

$ tree src
src/
├── api
│   ├── me.json
│   └── user.json
├── definitions
│   ├── primitive.json
│   └── user.json
└── main.json

src/main.json

src/api/me.json

src/api/user.json

src/definitions/primitive.json

src/definitions/user.json

bundle output

bundle output is this.

$ jsonknife bundle --src src/main.json --dst bundle.yaml

# if you want json output
$ jsonknife bundle --src src/main.json --dst bundle.json

bundle.yaml

deref output

deref output is this.

$ jsonknife deref --src src/main.json --dst deref.yaml

# if you want json output
$ jsonknife deref --src src/main.json --dst deref.json

deref.yaml

examples

$ tree src
src/
├── person.yaml
└── primitive.yaml

$ jsonknife deref --src src/person.yaml --dst dst/extracted.yaml --ref "#/definitions/person"
$ jsonknife examples dst/extracted.yaml --format yaml > dst/data.yaml

src/person.yaml

src/primitive.yaml

dst/extracted.yaml

dst/data.yaml