{"id":18994072,"url":"https://github.com/swaggest/json-cli","last_synced_at":"2025-05-12T14:52:03.941Z","repository":{"id":29534564,"uuid":"121966832","full_name":"swaggest/json-cli","owner":"swaggest","description":"JSON command-line swiss knife: diff, reordering, patch, pointer, validator, codegen","archived":false,"fork":false,"pushed_at":"2023-12-19T00:50:52.000Z","size":266,"stargazers_count":77,"open_issues_count":4,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T00:26:19.994Z","etag":null,"topics":["code-generator","json-patch","json-pointer","json-schema"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swaggest.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-18T16:05:37.000Z","updated_at":"2024-12-22T10:52:55.000Z","dependencies_parsed_at":"2023-12-19T04:12:27.620Z","dependency_job_id":"7e2b78a9-b3a8-4840-a93f-4e10f06bc227","html_url":"https://github.com/swaggest/json-cli","commit_stats":{"total_commits":84,"total_committers":3,"mean_commits":28.0,"dds":0.5476190476190477,"last_synced_commit":"147dbec6e6d75cf383fe5fe2c4ca88accefa742a"},"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fjson-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fjson-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fjson-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fjson-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swaggest","download_url":"https://codeload.github.com/swaggest/json-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238059009,"owners_count":19409607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generator","json-patch","json-pointer","json-schema"],"created_at":"2024-11-08T17:24:05.202Z","updated_at":"2025-02-10T05:09:39.496Z","avatar_url":"https://github.com/swaggest.png","language":"PHP","readme":"# JSON CLI multitool\n\n\u003cimg align=\"right\" width=\"100px\" height=\"100px\" alt=\"Swiss Knife\" src=\"./knife.svg\"\u003e\n\nA CLI app to find unordered diff between two `JSON` documents (based\non [`swaggest/json-diff`](https://github.com/swaggest/json-diff)), generate JSON Schema and Go/PHP code, pretty print,\nminify, yaml convert, etc....\n\n[![Build Status](https://travis-ci.org/swaggest/json-cli.svg?branch=master)](https://travis-ci.org/swaggest/json-cli)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/swaggest/json-cli/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/swaggest/json-cli/?branch=master)\n[![Code Climate](https://codeclimate.com/github/swaggest/json-cli/badges/gpa.svg)](https://codeclimate.com/github/swaggest/json-cli)\n[![Code Coverage](https://scrutinizer-ci.com/g/swaggest/json-cli/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/swaggest/json-cli/code-structure/master/code-coverage)\n[![Image Size](https://images.microbadger.com/badges/image/swaggest/json-cli.svg)](https://microbadger.com/images/swaggest/json-cli)\n![Code lines](https://sloc.xyz/github/swaggest/json-cli/?category=code)\n![Comments](https://sloc.xyz/github/swaggest/json-cli/?category=comments)\n\n## Purpose\n\n* To simplify changes review between two `JSON` files you can use a standard `diff` tool on rearranged\n  pretty-printed `JSON`.\n* To detect breaking changes by analyzing removals and changes from original `JSON`.\n* To keep original order of object sets (for\n  example `swagger.json` [parameters](https://swagger.io/docs/specification/describing-parameters/) list).\n* To make and apply JSON Patches, specified in [RFC 6902](http://tools.ietf.org/html/rfc6902) from the IETF.\n* To convert between YAML/JSON/PHP serialization.\n* To resolve `JSON Pointer` to data.\n* To resolve `JSON Pointer` to file position.\n* To validate JSON data against [`JSON Schema`](http://json-schema.org/).\n* To [generate or update](#buildschema) JSON Schema with instance value(s).\n* To [generate](#genjson) sample JSON value from JSON Schema.\n* To [render](#gengo) `JSON Schema` as [`Go`](http://golang.org/) structure.\n* To [render](#genphp) `JSON Schema` as `PHP` classes.\n* To [render](#genjsdoc) `JSON Schema` as `JSDoc` type definitions.\n* To [render](#genmarkdown) `JSON Schema` as `Markdown` documentation.\n\n## Installation\n\n### Docker\n\n```\ndocker run swaggest/json-cli json-cli --help\nv1.6.1 json-cli\nJSON CLI tool, https://github.com/swaggest/json-cli\n...\n```\n\n`json-cli` can load schema from stdin (using `-` as a file path) which can be handy with docker, for example:\n\n```\ncat ./tests/assets/swagger-schema.json | docker run -i --rm swaggest/json-cli json-cli gen-jsdoc -\n```\n\n### Composer\n\n[Install PHP Composer](https://getcomposer.org/doc/00-intro.md)\n\n```bash\ncomposer require swaggest/json-cli\n```\n\n## CLI tool\n\n### Usage\n\n```\nv1.9.0 json-cli\nJSON CLI tool, https://github.com/swaggest/json-cli\nUsage: \n   json-cli \u003caction\u003e\n   action   Action name\n            Allowed values: diff, apply, rearrange, diff-info, pretty-print, minify, replace, resolve,\n            resolve-pos, validate-schema, gen-go, gen-php, gen-jsdoc, gen-json, build-schema\n```\n\nInput paths can be .json/.yaml/.yml/.serialized files, file format is detected by file extension:\n\n* `.json` JSON\n* `.yaml`, `.yml` YAML\n* `.serialized` PHP serialization format\n\n#### Diff, make `JSON Patch` from two documents\n\n```\nv1.3.0 json-cli diff\nJSON CLI tool, https://github.com/swaggest/json-cli\nMake patch from two json documents, output to STDOUT\nUsage:\n   json-cli diff \u003coriginalPath\u003e \u003cnewPath\u003e\n   originalPath   Path to old (original) json file\n   newPath        Path to new json file\n\nOptions:\n   --rearrange-arrays    Rearrange arrays to match original\n   --pretty              Pretty-print result JSON\n   --output \u003coutput\u003e     Path to output result, default STDOUT\n   --to-yaml             Output in YAML format\n   --pretty-short        Pretty short format\n```\n\nExample:\n\nMaking `JSON Patch`\n\n```\njson-cli diff tests/assets/original.json tests/assets/new.json --rearrange-arrays --pretty-short\n[\n    {\"value\":4,\"op\":\"test\",\"path\":\"/key1/0\"},\n    {\"value\":5,\"op\":\"replace\",\"path\":\"/key1/0\"},\n    {\"op\":\"remove\",\"path\":\"/key2\"},\n    {\"op\":\"remove\",\"path\":\"/key3/sub0\"},\n    {\"value\":\"a\",\"op\":\"test\",\"path\":\"/key3/sub1\"},\n    {\"value\":\"c\",\"op\":\"replace\",\"path\":\"/key3/sub1\"},\n    {\"value\":\"b\",\"op\":\"test\",\"path\":\"/key3/sub2\"},\n    {\"value\":false,\"op\":\"replace\",\"path\":\"/key3/sub2\"},\n    {\"value\":0,\"op\":\"add\",\"path\":\"/key3/sub3\"},\n    {\"op\":\"remove\",\"path\":\"/key4/1/b\"},\n    {\"value\":false,\"op\":\"add\",\"path\":\"/key4/1/c\"},\n    {\"value\":1,\"op\":\"add\",\"path\":\"/key4/2/c\"},\n    {\"value\":\"wat\",\"op\":\"add\",\"path\":\"/key5\"}\n]\n```\n\n#### Apply `JSON Patch` to document\n\n```\nv1.3.0 json-cli apply\nJSON CLI tool, https://github.com/swaggest/json-cli\nApply patch to base json document, output to STDOUT\nUsage:\n   json-cli apply [patchPath] [basePath]\n   patchPath   Path to JSON patch file\n   basePath    Path to JSON base file\n\nOptions:\n   --pretty             Pretty-print result JSON\n   --output \u003coutput\u003e    Path to output result, default STDOUT\n   --to-yaml            Output in YAML format\n   --tolerate-errors    Continue on error\n```\n\n#### Rearrange JSON document to keep original order\n\n```\nv1.3.0 json-cli rearrange\nJSON CLI tool, https://github.com/swaggest/json-cli\nRearrange json document in the order of another (original) json document\nUsage:\n   json-cli rearrange \u003coriginalPath\u003e \u003cnewPath\u003e\n   originalPath   Path to old (original) json file\n   newPath        Path to new json file\n\nOptions:\n   --rearrange-arrays    Rearrange arrays to match original\n   --pretty              Pretty-print result JSON\n   --output \u003coutput\u003e     Path to output result, default STDOUT\n   --to-yaml             Output in YAML format\n```\n\nExample:\n\nUsing with standard `diff`\n\n```\njson-cli rearrange tests/assets/original.json tests/assets/new.json --rearrange-arrays --pretty | diff \u003c(json-cli pretty-print ./tests/assets/original.json) -\n3c3\n\u003c         4,\n---\n\u003e         5,\n8d7\n\u003c     \"key2\": 2,\n10,12c9,11\n\u003c         \"sub0\": 0,\n\u003c         \"sub1\": \"a\",\n\u003c         \"sub2\": \"b\"\n---\n\u003e         \"sub1\": \"c\",\n\u003e         \"sub2\": false,\n\u003e         \"sub3\": 0\n21c20\n\u003c             \"b\": false\n---\n\u003e             \"c\": false\n24c23,24\n\u003c             \"a\": 3\n---\n\u003e             \"a\": 3,\n\u003e             \"c\": 1\n26c26,27\n\u003c     ]\n---\n\u003e     ],\n\u003e     \"key5\": \"wat\"\n```\n\n#### Show difference between two JSON documents\n\n```\njson-cli diff-info --help\nv1.3.0 json-cli diff-info\nJSON CLI tool, https://github.com/swaggest/json-cli\nShow diff info for two JSON documents\nUsage:\n   json-cli diff-info \u003coriginalPath\u003e \u003cnewPath\u003e\n   originalPath   Path to old (original) json file\n   newPath        Path to new json file\n\nOptions:\n   --rearrange-arrays    Rearrange arrays to match original\n   --pretty              Pretty-print result JSON\n   --output \u003coutput\u003e     Path to output result, default STDOUT\n   --to-yaml             Output in YAML format\n   --with-contents       Add content to output\n   --with-paths          Add paths to output\n```\n\nExample:\n\nShowing differences in `JSON` mode\n\n```\njson-cli diff-info tests/assets/original.json tests/assets/new.json --with-paths --pretty\n{\n    \"addedCnt\": 4,\n    \"modifiedCnt\": 4,\n    \"removedCnt\": 3,\n    \"addedPaths\": [\n        \"/key3/sub3\",\n        \"/key4/0/c\",\n        \"/key4/2/c\",\n        \"/key5\"\n    ],\n    \"modifiedPaths\": [\n        \"/key1/0\",\n        \"/key3/sub1\",\n        \"/key3/sub2\",\n        \"/key4/0/a\",\n        \"/key4/1/a\",\n        \"/key4/1/b\"\n    ],\n    \"removedPaths\": [\n        \"/key2\",\n        \"/key3/sub0\",\n        \"/key4/0/b\"\n    ]\n}\n```\n\n#### Pretty-print JSON document or convert between formats\n\n```\njson-cli pretty-print --help\nv1.4.2 json-cli pretty-print\nJSON CLI tool, https://github.com/swaggest/json-cli\nPretty print JSON document\nUsage: \n   json-cli pretty-print \u003cpath\u003e\n   path   Path to JSON/YAML file\n\nOptions: \n   --output \u003coutput\u003e   Path to output result, default STDOUT\n   --to-yaml           Output in YAML format\n   --to-serialized     Output in PHP serialized format\n```\n\n#### Minify JSON document\n\n```\njson-cli minify --help\nv1.7.5 json-cli minify\nJSON CLI tool, https://github.com/swaggest/json-cli\nMinify JSON document\nUsage: \n   json-cli minify \u003cpath\u003e\n   path   Path to JSON/YAML file\n   \nOptions: \n   --output \u003coutput\u003e   Path to output result, default STDOUT\n   --to-serialized     Output in PHP serialized format      \n   --eol               Add line break to the output         \n```\n\nBash command to minify all JSON files in current directory.\n\n```\nfor f in *.json; do json-cli minify $f --output $f; done\n```\n\n#### Replace values in JSON document\n\n```\njson-cli replace --help\nv1.3.0 json-cli replace\nJSON CLI tool, https://github.com/swaggest/json-cli\nMinify JSON document\nUsage:\n   json-cli replace \u003cpath\u003e \u003csearch\u003e \u003creplace\u003e\n   path      Path to JSON/YAML file\n   search    Search JSON value\n   replace   Replace JSON value\n\nOptions:\n   --path-filter \u003cpathFilter\u003e   JSON path filter regex, example \"/definitions/.*/properties/deletedAt\"\n```\n\nExample:\n\n```\njson-cli replace swagger.json '{\"type\": \"string\",\"format\": \"date-time\"}' '{\"type\": \"string\",\"format\": \"date-time\",\"x-nullable\":true}' --path-filter '/definitions/.*/properties/deletedAt' --output swagger-fixed.json\n```\n\n#### Resolve `JSON Pointer` to a value from document\n\n```\njson-cli resolve --help\nv1.3.0 json-cli resolve\nJSON CLI tool, https://github.com/swaggest/json-cli\nUsage:\n   json-cli resolve [path] [pointer]\n   path      Path to JSON/YAML file\n   pointer   JSON Pointer, example /key4/1/a\n```\n\nExample:\n\n```\njson-cli resolve tests/assets/original.json /key4/1\n{\"a\":2,\"b\":false}\n```\n\n#### Resolve `JSON Pointer` to a position in JSON file (line:col)\n\n```\njson-cli resolve-pos --help\nv1.3.0 json-cli resolve-pos\nJSON CLI tool, https://github.com/swaggest/json-cli\nUsage:\n   json-cli resolve-pos [path] [pointer]\n   path      Path to JSON file\n   pointer   JSON Pointer, example /key4/1/a\n\nOptions:\n   --dump-all    Dump all pointer positions from JSON\n```\n\nExample:\n\n```\njson-cli resolve-pos tests/assets/original.json /key4/1\n19:9\n```\n\n#### Validate JSON document against `JSON Schema`\n\n```\njson-cli validate-schema --help\nv1.4.0 json-cli validate-schema\nJSON CLI tool, https://github.com/swaggest/json-cli\nUsage:\n   json-cli validate-schema \u003cdata\u003e [schema]\n   data     Path to data (JSON/YAML)\n   schema   Path to schema, default JSON Schema\n```\n\nExample:\n\n```\njson-cli validate-schema tests/assets/sample-data.json tests/assets/sample-schema.json\nData is invalid\nNo valid results for oneOf {\n 0: String expected, 5 received at #-\u003eoneOf[0]\n 1: Value more than 10 expected, 5 received at #-\u003eoneOf[1]-\u003e$ref[#/definitions/int10plus]\n}\n```\n\n#### \u003ca name=\"buildschema\"\u003e\u003c/a\u003e Generate/update `JSON Schema` from instance value(s).\n\nNew or existing schema is synchronized to match data samples.\n\n```\nv1.7.8 json-cli build-schema\nJSON CLI tool, https://github.com/swaggest/json-cli\nUsage: \n   json-cli build-schema \u003cdata\u003e [schema]\n   data     Path to data (JSON/YAML)\n   schema   Path to parent schema   \n   \nOptions: \n   --ptr-in-schema \u003cptrInSchema\u003e           JSON pointer to structure in root schema, default #                      \n   --ptr-in-data \u003cptrInData\u003e               JSON pointer to structure in data, default #                             \n   --jsonl                                 Data is a stream of JSON Lines                                           \n   --use-nullable                          Use `nullable: true` instead of `type: null`, OAS 3.0 compatibility      \n   --use-xnullable                         Use `x-nullable: true` instead of `type: null`, Swagger 2.0 compatibility\n   --defs-ptr \u003cdefsPtr\u003e                    Location to put new definitions. default: \"#/definitions/\"               \n   --collect-examples                      Collect scalar values example                                            \n   --heuristic-required                    Mark properties that are available in all samples as `required`.         \n   --additional-data \u003cadditionalData...\u003e   Additional paths to data                                                 \n   --pretty                                Pretty-print result JSON                                                 \n   --output \u003coutput\u003e                       Path to output result, default STDOUT                                    \n   --to-yaml                               Output in YAML format                                                    \n   --to-serialized                         Output in PHP serialized format                                          \n```\n\nBasic example:\n\n```\njson-cli build-schema tests/assets/original.json \n\n{\"properties\":{\"key1\":{\"items\":{\"type\":\"integer\"},\"type\":\"array\"},\"key2\":{\"type\":\"integer\"},\"key3\":{\"$ref\":\"#/definitions/key3\"},\"key4\":{\"items\":{\"$ref\":\"#/definitions/key4.element\"},\"type\":\"array\"}},\"type\":\"object\",\"definitions\":{\"key3\":{\"properties\":{\"sub0\":{\"type\":\"integer\"},\"sub1\":{\"type\":\"string\"},\"sub2\":{\"type\":\"string\"}},\"type\":\"object\"},\"key4.element\":{\"properties\":{\"a\":{\"type\":\"integer\"},\"b\":{\"type\":\"boolean\"}},\"type\":\"object\"}}}\n```\n\nAdvanced example:\n\n```\njson-cli build-schema dump-responses.jsonl ./acme-service/swagger.json --ptr-in-schema \"#/definitions/Orders\" --jsonl --ptr-in-data \"#/responseValue\" --pretty --output swagger.json\n```\n\nUpdates `swagger.json` with actual response samples provided in `dump-responses.jsonl`.\n\n#### \u003ca name=\"gengo\"\u003e\u003c/a\u003e Generate [`Go`](http://golang.org/) structure from `JSON Schema`.\n\n`Go` code is built using [`swaggest/go-code-builder`](http://github.com/swaggest/go-code-builder).\n\n```\nv1.8.0 json-cli gen-go\nJSON CLI tool, https://github.com/swaggest/json-cli\nGenerate Go code from JSON schema\nUsage: \n   json-cli gen-go \u003cschema\u003e\n   schema   Path to JSON schema file\n\nOptions: \n   --ptr-in-schema \u003cptrInSchema...\u003e          JSON pointers to structure in root schema, default #\n   --def-ptr \u003cdefPtr...\u003e                     Definitions pointers to strip from symbol names, default #/definitions\n   --patches \u003cpatches...\u003e                    JSON patches to apply to schema file before processing, merge patches are also supported\n   --output \u003coutput\u003e                         Path to output .go file, STDOUT is used by default\n   --package-name \u003cpackageName\u003e              Go package name, default \"entities\"\n   --root-name \u003crootName\u003e                    Go root struct name, default \"Structure\", only used for # pointer\n   --show-const-properties                   Show properties with constant values, hidden by default\n   --keep-parent-in-property-names           Keep parent prefix in property name, removed by default\n   --ignore-nullable                         Add `omitempty` to nullable properties, removed by default\n   --ignore-xgo-type                         Ignore `x-go-type` in schema to skip generation\n   --with-zero-values                        Use pointer types to avoid zero value ambiguity\n   --enable-xnullable                        Add `null` to types if `x-nullable` or `nullable` is available\n   --enable-default-additional-properties    Add field property for undefined `additionalProperties`\n   --fluent-setters                          Add fluent setters to struct fields\n   --ignore-required                         Ignore if property is required when deciding on pointer type or omitempty\n   --renames \u003crenames...\u003e                    Map of exported symbol renames, example From:To\n   --with-tests                              Generate (un)marshaling tests for entities (experimental feature)\n   --require-xgenerate                       Generate properties with `x-generate: true` only\n   --validate-required                       Generate validation code to check required properties during unmarshal\n   --name-tags \u003cnameTags...\u003e                 Set additional field tags with property name, example \"msgp bson\"\n```\n\nExample:\n\n```\njson-cli gen-go http://json-schema.org/learn/examples/address.schema.json\n```\n\n```\n// Code generated by github.com/swaggest/json-cli v1.6.3, DO NOT EDIT.\n\n// Package entities contains JSON mapping structures.\npackage entities\n\n\n\n// Structure structure is generated from \"#\".\n//\n// An address similar to http://microformats.org/wiki/h-card.\ntype Structure struct {\n        PostOfficeBox   string `json:\"post-office-box,omitempty\"`\n        ExtendedAddress string `json:\"extended-address,omitempty\"`\n        StreetAddress   string `json:\"street-address,omitempty\"`\n        Locality        string `json:\"locality,omitempty\"`\n        Region          string `json:\"region,omitempty\"`\n        PostalCode      string `json:\"postal-code,omitempty\"`\n        CountryName     string `json:\"country-name,omitempty\"`\n}\n```\n\nAdvanced example:\n\n```\njson-cli gen-go \"https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0-rc1/examples/1.2.0/streetlights.yml\" \\\n    --ptr-in-schema \"#/components/messages/lightMeasured/payload\" \"#/components/messages/turnOnOff/payload\" \\\n    --def-ptr \"#/components/schemas\" \\\n    --package-name message \\\n    --output ./entities.go\n\ncat ./entities.go\n```\n\n```\n// Code generated by github.com/swaggest/json-cli v1.6.3, DO NOT EDIT.\n\n// Package message contains JSON mapping structures.\npackage message\n\nimport (\n        \"fmt\"\n        \"time\"\n)\n\n// LightMeasuredPayload structure is generated from \"#/components/schemas/lightMeasuredPayload\".\ntype LightMeasuredPayload struct {\n        Lumens int64      `json:\"lumens,omitempty\"` // Light intensity measured in lumens.\n        SentAt *time.Time `json:\"sentAt,omitempty\"` // Date and time when the message was sent.\n}\n\n// TurnOnOffPayload structure is generated from \"#/components/schemas/turnOnOffPayload\".\ntype TurnOnOffPayload struct {\n        Command TurnOnOffPayloadCommand `json:\"command,omitempty\"` // Whether to turn on or off the light.\n        SentAt  *time.Time              `json:\"sentAt,omitempty\"`  // Date and time when the message was sent.\n}\n\n// TurnOnOffPayloadCommand is an enum type.\ntype TurnOnOffPayloadCommand string\n\n// TurnOnOffPayloadCommand values enumeration.\nconst (\n        TurnOnOffPayloadCommandOn = TurnOnOffPayloadCommand(\"on\")\n        TurnOnOffPayloadCommandOff = TurnOnOffPayloadCommand(\"off\")\n)\n\n// MarshalJSON encodes JSON.\nfunc (i TurnOnOffPayloadCommand) MarshalJSON() ([]byte, error) {\n        switch i {\n        case TurnOnOffPayloadCommandOn:\n        case TurnOnOffPayloadCommandOff:\n\n        default:\n                return nil, fmt.Errorf(\"unexpected TurnOnOffPayloadCommand value: %v\", i)\n        }\n\n        return json.Marshal(string(i))\n}\n\n// UnmarshalJSON decodes JSON.\nfunc (i *TurnOnOffPayloadCommand) UnmarshalJSON(data []byte) error {\n        var ii string\n        err := json.Unmarshal(data, \u0026ii)\n        if err != nil {\n                return err\n        }\n        v := TurnOnOffPayloadCommand(ii)\n        switch v {\n        case TurnOnOffPayloadCommandOn:\n        case TurnOnOffPayloadCommandOff:\n\n        default:\n                return fmt.Errorf(\"unexpected TurnOnOffPayloadCommand value: %v\", v)\n        }\n\n        *i = v\n        return nil\n}\n```\n\n#### \u003ca name=\"genphp\"\u003e\u003c/a\u003e Generate `PHP` classes from `JSON Schema`.\n\n`PHP` code is built using [`swaggest/php-code-builder`](http://github.com/swaggest/php-code-builder).\n\nGenerated classes require [`swaggest/json-schema`](http://github.com/swaggest/php-json-schema) package.\n\n```\nv1.8.0 json-cli gen-php\nJSON CLI tool, https://github.com/swaggest/json-cli\nGenerate PHP code from JSON schema\nUsage: \n   json-cli gen-php \u003cschema\u003e --ns \u003cns\u003e --ns-path \u003cnsPath\u003e\n   schema   Path to JSON schema file\n\nOptions: \n   --ptr-in-schema \u003cptrInSchema...\u003e           JSON pointers to structure in root schema, default #\n   --def-ptr \u003cdefPtr...\u003e                      Definitions pointers to strip from symbol names, default #/definitions\n   --patches \u003cpatches...\u003e                     JSON patches to apply to schema file before processing, merge patches are also supported\n   --ns \u003cns\u003e                                  Namespace to use for generated classes, example \\MyClasses\n   --ns-path \u003cnsPath\u003e                         Path to store generated classes, example ./src/MyClasses\n   --root-name \u003crootName\u003e                     Go root struct name, default \"Structure\", only used for # pointer\n   --setters                                  Build setters\n   --getters                                  Build getters\n   --no-enum-const                            Do not create constants for enum/const values\n   --declare-property-defaults                Use default values to initialize properties\n   --build-additional-properties-accessors    Build accessors for additionalProperties\n```\n\nAdvanced example:\n\n```\nmkdir ./StreetLights\n\njson-cli gen-php \"https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0-rc1/examples/1.2.0/streetlights.yml\" \\\n    --ptr-in-schema \"#/components/messages/lightMeasured/payload\" \"#/components/messages/turnOnOff/payload\" \\\n    --def-ptr \"#/components/schemas\" \\\n    --ns MyApp\\\\StreetLights \\\n    --ns-path ./StreetLights\n    \ncat ./StreetLights/*\n```\n\n```\nClasses are generated in /path/to/StreetLights\n\n\u003c?php\n/**\n * @file ATTENTION!!! The code below was carefully crafted by a mean machine.\n * Please consider to NOT put any emotional human-generated modifications as the splendid AI will throw them away with no mercy.\n */\n\nnamespace MyApp\\StreetLights;\n\nuse Swaggest\\JsonSchema\\Constraint\\Properties;\nuse Swaggest\\JsonSchema\\Schema;\nuse Swaggest\\JsonSchema\\Structure\\ClassStructure;\n\n\n/**\n * Built from #/components/schemas/lightMeasuredPayload\n *  \u003c- streetlights.yml#/components/messages/lightMeasured/payload\n */\nclass LightMeasuredPayload extends ClassStructure\n{\n    /** @var int Light intensity measured in lumens. */\n    public $lumens;\n\n    /** @var string Date and time when the message was sent. */\n    public $sentAt;\n\n    /**\n     * @param Properties|static $properties\n     * @param Schema $ownerSchema\n     */\n    public static function setUpProperties($properties, Schema $ownerSchema)\n    {\n        $properties-\u003elumens = Schema::integer();\n        $properties-\u003elumens-\u003edescription = \"Light intensity measured in lumens.\";\n        $properties-\u003elumens-\u003eminimum = 0;\n        $properties-\u003esentAt = Schema::string();\n        $properties-\u003esentAt-\u003edescription = \"Date and time when the message was sent.\";\n        $properties-\u003esentAt-\u003eformat = \"date-time\";\n        $properties-\u003esentAt-\u003esetFromRef('#/components/schemas/sentAt');\n        $ownerSchema-\u003etype = 'object';\n        $ownerSchema-\u003ecomponents = (object)array(\n            'schemas' =\u003e\n            (object)(array(\n                 'sentAt' =\u003e\n                (object)(array(\n                     'description' =\u003e 'Date and time when the message was sent.',\n                     'type' =\u003e 'string',\n                     'format' =\u003e 'date-time',\n                )),\n            )),\n        );\n        $ownerSchema-\u003esetFromRef('streetlights.yml#/components/messages/lightMeasured/payload');\n    }\n}\u003c?php\n/**\n * @file ATTENTION!!! The code below was carefully crafted by a mean machine.\n * Please consider to NOT put any emotional human-generated modifications as the splendid AI will throw them away with no mercy.\n */\n\nnamespace MyApp\\StreetLights;\n\nuse Swaggest\\JsonSchema\\Constraint\\Properties;\nuse Swaggest\\JsonSchema\\Schema;\nuse Swaggest\\JsonSchema\\Structure\\ClassStructure;\n\n\n/**\n * Built from #/components/schemas/turnOnOffPayload\n *  \u003c- streetlights.yml#/components/messages/turnOnOff/payload\n */\nclass TurnOnOffPayload extends ClassStructure\n{\n    const ON = 'on';\n\n    const OFF = 'off';\n\n    /** @var string Whether to turn on or off the light. */\n    public $command;\n\n    /** @var string Date and time when the message was sent. */\n    public $sentAt;\n\n    /**\n     * @param Properties|static $properties\n     * @param Schema $ownerSchema\n     */\n    public static function setUpProperties($properties, Schema $ownerSchema)\n    {\n        $properties-\u003ecommand = Schema::string();\n        $properties-\u003ecommand-\u003eenum = array(\n            self::ON,\n            self::OFF,\n        );\n        $properties-\u003ecommand-\u003edescription = \"Whether to turn on or off the light.\";\n        $properties-\u003esentAt = Schema::string();\n        $properties-\u003esentAt-\u003edescription = \"Date and time when the message was sent.\";\n        $properties-\u003esentAt-\u003eformat = \"date-time\";\n        $properties-\u003esentAt-\u003esetFromRef('#/components/schemas/sentAt');\n        $ownerSchema-\u003etype = 'object';\n        $ownerSchema-\u003ecomponents = (object)array(\n            'schemas' =\u003e\n            (object)(array(\n                 'sentAt' =\u003e\n                (object)(array(\n                     'description' =\u003e 'Date and time when the message was sent.',\n                     'type' =\u003e 'string',\n                     'format' =\u003e 'date-time',\n                )),\n            )),\n        );\n        $ownerSchema-\u003esetFromRef('streetlights.yml#/components/messages/turnOnOff/payload');\n    }\n}\n```\n\n#### \u003ca name=\"genjsdoc\"\u003e\u003c/a\u003e Generate `JSDoc` type definitions from `JSON Schema`.\n\n```\nv1.8.4 json-cli gen-jsdoc\nJSON CLI tool, https://github.com/swaggest/json-cli\nGenerate JSDoc code from JSON schema\nUsage: \n   json-cli gen-jsdoc \u003cschema\u003e\n   schema   Path to JSON schema file\n   \nOptions: \n   --ptr-in-schema \u003cptrInSchema...\u003e   JSON pointers to structure in root schema, default #                                 \n   --def-ptr \u003cdefPtr...\u003e              Definitions pointers to strip from symbol names, default #/definitions                  \n   --patches \u003cpatches...\u003e             JSON patches to apply to schema file before processing, merge patches are also supported\n```\n\nExample:\n\n```\njson-cli gen-jsdoc \"https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0-rc1/examples/1.2.0/streetlights.yml\" \\\n    --ptr-in-schema \"#/components/messages/lightMeasured/payload\" \"#/components/messages/turnOnOff/payload\" \\\n    --def-ptr \"#/components/schemas\"\n```\n\n```\n/**\n * @typedef ComponentsMessagesLightMeasuredPayload\n * @type {object}\n * @property {number} lumens - Light intensity measured in lumens.\n * @property {string} sentAt - Date and time when the message was sent.\n */\n\n/**\n * @typedef ComponentsMessagesTurnOnOffPayload\n * @type {object}\n * @property {string} command - Whether to turn on or off the light.\n * @property {string} sentAt - Date and time when the message was sent.\n */\n\n```\n\n#### \u003ca name=\"genmarkdown\"\u003e\u003c/a\u003e Generate `Markdown` documentation from `JSON Schema`.\n\n```\nv1.10.0 json-cli gen-markdown\nJSON CLI tool, https://github.com/swaggest/json-cli\nGenerate Markdown document from JSON schema\nUsage: \n   json-cli gen-markdown \u003cschema\u003e\n   schema   Path to JSON schema file, use `-` for STDIN\n   \nOptions: \n   --ptr-in-schema \u003cptrInSchema...\u003e   JSON pointers to structure in root schema, default #                                    \n   --def-ptr \u003cdefPtr...\u003e              Definitions pointers to strip from symbol names, default #/definitions                  \n   --patches \u003cpatches...\u003e             JSON patches to apply to schema file before processing, merge patches are also supported   \n```\n\nExample:\n\n```\njson-cli gen-markdown \"https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0-rc1/examples/1.2.0/streetlights.yml\" \\\n    --ptr-in-schema \"#/components/messages/lightMeasured/payload\" \"#/components/messages/turnOnOff/payload\" \\\n    --def-ptr \"#/components/schemas\"\n```\n\n```markdown\n# Types\n\n* [`ComponentsMessagesLightMeasuredPayload`](#componentsmessageslightmeasuredpayload)\n* [`ComponentsMessagesTurnOnOffPayload`](#componentsmessagesturnonoffpayload)\n* [`LightMeasuredPayloadLumens`](#lightmeasuredpayloadlumens)\n\n\n\n\n### \u003ca id=\"componentsmessageslightmeasuredpayload\"\u003e\u003c/a\u003eComponentsMessagesLightMeasuredPayload\n\n\n\n|Property|Type                                                                 |Description                             |\n|--------|---------------------------------------------------------------------|----------------------------------------|\n|`lumens`|[`LightMeasuredPayloadLumens`](#lightmeasuredpayloadlumens), `Number`|Light intensity measured in lumens.     |\n|`sentAt`|`String`, Format: `date-time`                                        |Date and time when the message was sent.|\n\n\n### \u003ca id=\"componentsmessagesturnonoffpayload\"\u003e\u003c/a\u003eComponentsMessagesTurnOnOffPayload\n\n\n\n|Property |Type                         |Description                             |\n|---------|-----------------------------|----------------------------------------|\n|`command`|`'on'`, \u003cbr\u003e`'off'`          |Whether to turn on or off the light.    |\n|`sentAt` |`String`, Format: `date-time`|Date and time when the message was sent.|\n\n\n### \u003ca id=\"lightmeasuredpayloadlumens\"\u003e\u003c/a\u003eLightMeasuredPayloadLumens\nLight intensity measured in lumens.\n\n|Constraint|Value|\n|----------|-----|\n|minimum   |0    |\n```\n\n#### \u003ca name=\"genjson\"\u003e\u003c/a\u003e Generate `JSON` sample from `JSON Schema`.\n\n```\nv1.9.0 json-cli gen-json\nJSON CLI tool, https://github.com/swaggest/json-cli\nGenerate JSON sample from JSON schema\nUsage: \n   json-cli gen-json \u003cschema\u003e\n   schema   Path to JSON schema file, use `-` for STDIN\n\nOptions: \n   --ptr-in-schema \u003cptrInSchema...\u003e   JSON pointers to structure in root schema, default #\n   --def-ptr \u003cdefPtr...\u003e              Definitions pointers to strip from symbol names, default #/definitions\n   --patches \u003cpatches...\u003e             JSON patches to apply to schema file before processing, merge patches are also supported\n   --max-nesting \u003cmaxNesting\u003e         Max nesting level, default 10\n   --default-additional-properties    Treat non-existent `additionalProperties` as `additionalProperties: true`\n   --rand-seed \u003crandSeed\u003e             Integer random seed for deterministic output\n   --pretty                           Pretty-print result JSON\n   --output \u003coutput\u003e                  Path to output result, default STDOUT\n   --to-yaml                          Output in YAML format\n   --to-serialized                    Output in PHP serialized format\n```\n\n```\necho '{\n  \"properties\": {\n    \"foo\": {\n      \"type\": \"string\",\n      \"example\": \"abc\"\n    },\n    \"bar\": {\n      \"enum\": [\"baz\", \"quux\"]\n    }\n  }\n}' | ./bin/json-cli gen-json - --rand-seed 10\n```\n\n```\n{\"foo\":\"abc\",\"bar\":\"baz\"}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswaggest%2Fjson-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswaggest%2Fjson-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswaggest%2Fjson-cli/lists"}