{"id":19197874,"url":"https://github.com/flarebyte/json-commander","last_synced_at":"2026-04-30T07:40:38.234Z","repository":{"id":30822626,"uuid":"34379929","full_name":"flarebyte/json-commander","owner":"flarebyte","description":"Commands generator for the update of json documents","archived":false,"fork":false,"pushed_at":"2016-04-13T20:27:09.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-17T19:02:18.703Z","etag":null,"topics":["npm-package"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/flarebyte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-22T08:57:01.000Z","updated_at":"2023-05-13T07:11:28.000Z","dependencies_parsed_at":"2022-06-26T15:22:35.102Z","dependency_job_id":null,"html_url":"https://github.com/flarebyte/json-commander","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarebyte%2Fjson-commander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarebyte%2Fjson-commander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarebyte%2Fjson-commander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarebyte%2Fjson-commander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flarebyte","download_url":"https://codeload.github.com/flarebyte/json-commander/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240271540,"owners_count":19774859,"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":["npm-package"],"created_at":"2024-11-09T12:19:03.851Z","updated_at":"2026-04-30T07:40:38.184Z","avatar_url":"https://github.com/flarebyte.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-url]][daviddm-image]\n\n\u003e Commands generator for the update of json documents\n\nThis library provides some commands for manipulating a json configuration file.\nThis configuration file must respect a json-schema.\n\nBecause json-commander is aware of the schema, it is able to provide a smart assistance which can be pretty handy if you are implementing a CLI.\n\nYou can find at the bottom of this documentation, an example using the commander package, but json-commander is not tied to any specific CLI library.\n\n## Install\n\n```sh\n$ npm install --save json-commander\n```\n\n\n## Usage\n\n```js\nvar jsonCommander = require('json-commander');\nvar cmdr = jsonCommander({schema: __dirname + \"myschema.json\"});\n\nvar someJson = {\n\ttitle: \"Some title\",\n\tcontributors: [\n\t\t{name: \"Olivier\"},\n\t\t{name: \"Aradhna\"},\n\t\t{name: \"Roy\"}\n\t]\n\t};\n\n    cmdr.evaluate(someJson, ['get', 'contributors[1].name']);\n    //will return Aradhna\n```\n\n### Help\n\nDisplay the help for the supported commands.\n\n```js\n\tcmdr.evaluate(someJson, ['help']);\n\t//Will return some help\n\n```\n\n### All\n\nDisplay the new configuration.\n\n```js\n\tcmdr.evaluate(someJson, ['all');\n\t//will return someJson\n```\n\n### Check\n\nCheck whether the configuration is valid or not.\n\n```js\n\tcmdr.evaluate(someJson, ['check']);\n\t//will return valid or invalid\n```\n\n\n### Copy\n\nCopy a value between two paths.\n\n```js\n\tcmdr.evaluate(someJson, ['copy', 'contributors[1]', 'contributors[2]']);\n\t//will replace Roy by olivier\n```\n\n\n### Del\n\nDelete the value at the given path.\n\n```js\n\tcmdr.evaluate(someJson, ['del', 'contributors[2]']);\n\t//will delete Roy\n```\n\n\n### Get\n\nGet the value at the given path.\n\n```js\n\tcmdr.evaluate(someJson, ['get', 'title']);\n\t//will return \"Some title\"\n```\n\n\n### Insert\n\nInsert a blank row.\n\n```js\n\tcmdr.evaluate(someJson, ['insert', 'contributors','1']);\n\t//will insert an empty contributor after Aradhna\n```\n\n### Set\n\nSet the value at the given path.\n\n```js\n\tcmdr.evaluate(someJson, ['set', 'title','Much better title']);\n\t//Will replace 'Some title' by 'Much better title'\n```\n\n### Schema\n\nDisplay the schema with all the possible paths.\n\n```js\n\tcmdr.evaluate(someJson, ['schema']);\n\t//Will display the schema\n```\n\n### Creating a CLI\n\nJson-commander can easily used to create a CLI.\n\nRequires:\n[commander](https://www.npmjs.com/package/commander)\n[solace](https://www.npmjs.com/package/solace)\n[confiture](https://www.npmjs.com/package/confiture)\n\nThe setup program:\n```js\nimport solaceCreator from 'solace';\nimport confiture from 'confiture';\n\nconst solace = solaceCreator({});\nconst configurator = confiture({/*check doc*/});\n\nconst setupProgram = (cmd, other) =\u003e {\n    const hasOther = !_.isEmpty(other);\n    const cmdOptions = hasOther ? [cmd].concat(other) : [cmd];\n    const isWriting = cmd === 'set' || cmd === 'copy' || cmd === 'del' || cmd === 'insert';\n    if (isWriting) {\n      cmdr.evaluate(unalteredConf, cmdOptions);\n      configurator.saveSync(unalteredConf);\n      solace.log(`${cmd} done.`);\n    } else {\n      const evaluation = cmdr.evaluate(unalteredConf, cmdOptions);\n      solace.log(evaluation);\n    }\n  };\n```\n\nWith commander to provide a CLI:\n```js\nimport program from 'commander';\nprogram.command('setup \u003ccmd\u003e [other...]')\n  .description('configure My CLI')\n  .action(setupProgram);\n```\n\n\n## License\n\nMIT © [Olivier Huin]()\n\n\n[npm-url]: https://npmjs.org/package/json-commander\n[npm-image]: https://badge.fury.io/js/json-commander.svg\n[travis-url]: https://travis-ci.org/flarebyte/json-commander\n[travis-image]: https://travis-ci.org/flarebyte/json-commander.svg?branch=master\n[daviddm-url]: https://david-dm.org/flarebyte/json-commander.svg?theme=shields.io\n[daviddm-image]: https://david-dm.org/flarebyte/json-commander\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflarebyte%2Fjson-commander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflarebyte%2Fjson-commander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflarebyte%2Fjson-commander/lists"}