{"id":21451484,"url":"https://github.com/db-developer/grunt-jsonfile","last_synced_at":"2025-07-14T22:30:37.677Z","repository":{"id":50613300,"uuid":"188244666","full_name":"db-developer/grunt-jsonfile","owner":"db-developer","description":"use grunt to create and modify jsonfiles","archived":false,"fork":false,"pushed_at":"2023-11-24T08:29:10.000Z","size":1071,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-18T12:29:31.403Z","etag":null,"topics":["grunt","javascript","json","plugin","templating"],"latest_commit_sha":null,"homepage":"https://www.slashlib.org/?page_id=504","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/db-developer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2019-05-23T13:56:38.000Z","updated_at":"2024-06-19T19:07:45.270Z","dependencies_parsed_at":"2023-01-30T01:45:49.140Z","dependency_job_id":"0fb26617-cafa-4b3c-bc42-683a95df9a6b","html_url":"https://github.com/db-developer/grunt-jsonfile","commit_stats":{"total_commits":120,"total_committers":3,"mean_commits":40.0,"dds":0.04166666666666663,"last_synced_commit":"ce859205c9c3b9458b92dc1322960d61dab5db84"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-developer%2Fgrunt-jsonfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-developer%2Fgrunt-jsonfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-developer%2Fgrunt-jsonfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-developer%2Fgrunt-jsonfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/db-developer","download_url":"https://codeload.github.com/db-developer/grunt-jsonfile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225999721,"owners_count":17557640,"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":["grunt","javascript","json","plugin","templating"],"created_at":"2024-11-23T04:22:33.938Z","updated_at":"2024-11-23T04:22:34.534Z","avatar_url":"https://github.com/db-developer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grunt-jsonfile\n\nuse objects or json files as template, to create, modify and distribute jsonfiles.  \n\n[![npm version](https://img.shields.io/npm/v/grunt-jsonfile?color=blue)](https://www.npmjs.com/package/grunt-jsonfile)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![jsdoc](https://img.shields.io/static/v1?label=jsdoc\u0026message=%20api%20\u0026color=blue)](https://jsdoc.app/)\n[![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](https://gruntjs.com/)\n[![codecov](https://codecov.io/gh/db-developer/grunt-jsonfile/branch/master/graph/badge.svg)](https://codecov.io/gh/db-developer/grunt-jsonfile)\n[![Build Status](https://travis-ci.com/db-developer/grunt-jsonfile.svg?branch=master)](https://travis-ci.com/db-developer/grunt-jsonfile)\n[![dependencies](https://img.shields.io/librariesio/release/npm/grunt-jsonfile)](https://libraries.io/)\n\nWhen running a complex make for various environments, types like [test|production]\nand/or os targets, json configuration files might be required, which differ in\nspecific properties.  \n\ngrunt-jsonfile offers the opportunity to:\n\n* provide json templates\n* customize templates by merging in values\n* customize templates by removing values\n* customize templates by updating values\n* write modified templates to json files into custom (build) directories\n* use project package.json files as templates\n\n## content ##\n\n* Usage (see further down this page)\n  * [Getting started guide](#getting-started)\n  * [Usage and examples](#usage)\n\n* Developers\n  * [Testing grunt-jsonfile](docs/grunt.md#testing)\n  * [Code coverage of tests for grunt-jsonfile](docs/grunt.md#code-coverage)\n  * [Build grunt-jsonfile from scratch](docs/grunt.md#building)\n  * [NPM integration of grunt-jsonfile](docs/grunt.md#npm_integration)\n  * [Frameworks used for testing, building, etc.](docs/frameworks.md)\n  * [API of package grunt-jsonfile](docs/api.index.md)\n\n[Changelog](CHANGELOG.md)\n\n## getting started ##\n\nThis guide assumes, that you are familiar with the use of [npm](https://npmjs.com \"Homepage of npm\") and [grunt](https://gruntjs.com \"Homepage of grunt\").  \nThe plugin can be installed by the following command:\n\n\u003ccode\u003enpm install grunt-jsonfiles --save-dev\u003c/code\u003e\n\nDo note forget to install the peer dependencies.  \nOnce installed, the plugin may be loaded from within your gruntfile:\n\n\u003ccode\u003egrunt.loadNpmTasks( \"jsonfiles\" );\u003c/code\u003e\n\nSetup the task configuration as described below (see usage) and run the task:\n\n\u003ccode\u003egrunt jsonfiles\u003c/code\u003e\n\nOf cause, the task can be integrated into any complex build process.\n\n## usage ##\n\n### defining an EOF ###\n\nIf option.EOF is truthy, jsonfiles will close with an operating system specifc\nEOL (end of line)\n\n```javascript\n\nconst jsonfile = {\n  options: {\n    EOF: true\n  }\n};\n```\n\n### defining templates ###\n\nThe following example defines two templates in the options section of 'jsonfile'.\n\n```javascript\n// Templates are identified by name. This example defines two templates, which\n// can be referenced by \"tmpl1\" and \"tmpl2\"\n\nconst jsonfile = {\n  options:{\n    templates: {\n      tmpl1:  \"config/template.json\",   // strings will be interpreted as path to\n                                        // json files, which will be required and\n                                        // used as template.\n      tmpl2:  {                         // objects will directly be used as\n        pname1:     5,                  // template\n        pname2:     true,\n        pname3:     \"value\",\n        aproperty:  \"a aproperty will be deleted\"\n      }\n    }\n  }\n};\n```\n\nThe following examples define templates directly within their targets.\n\n```javascript\nconst BUILD    = \"...some path\";\nconst jsonfile = {\n  target1: {\n    template: \"config/template.json\",   // template is a string value, and does not\n                                        // reference a template in  options.templates.\n                                        // Therefor it will be interpreted as path to\n                                        // a json file, which will be required.\n    dest:     `${ BUILD }/file.json`,   // write the result to this file.\n  }\n};\n```\n\n```javascript\nconst BUILD    = \"...some path\";\nconst jsonfile = {\n  target1: {\n    template: {                         // a template object\n      pname1:     5,\n      pname2:     true,\n      pname3:     \"value\",\n      aproperty:  \"a aproperty will be deleted\"\n    },\n    dest:     `${ BUILD }/file.json`,   // write the result to this file.\n  }\n};\n```\n\n### referencing templates ###\n\n```javascript\n// Target 'target1' references a template in options.templates\n\nconst BUILD    = \"...some path\";\nconst jsonfile = {\n  options:{\n    templates: {\n      tmpl1:  \"config/template.json\"    // read the json file and use the resulting\n                                        // object as template.\n    }\n  },\n  target1: {\n    template: \"tmpl1\",                  // template is a string value, and references\n                                        // a template in options.templates which will\n                                        // be used.\n    dest: [                             // write the result to all files in this array\n            `${ BUILD }/1/file.json`,   \n            `${ BUILD }/2/file.json`,\n            `${ BUILD }/3/file.json`\n          ]\n  }\n};\n```\n\n### setting template values ###\n\nSetting a value to a property of a template can mean:\n* creating a template property if it did not yet exist\n* overwriting the value of an existing template property\n\n```javascript\nconst BUILD    = \"...some path\";\nconst jsonfile = {\n  target1: {\n    template: {                         // a template object\n      pname1:     5,\n      pname2:     true,\n      pname3:     { key: \"value\" },\n      aproperty:  \"a aproperty will be deleted\"\n    },\n    dest:     `${ BUILD }/file.json`,   // write the result to this file.\n    set: {\n      pname1: \"value 5 replaced\",       // this will set template.pname1 to\n                                        // \"value 5 replaced\"\n      pname2: undefined,                // this will set template.pname2 to\n                                        // undefined\n      pname3: { other: \"instance\" },    // this will set template.pname3 to\n                                        // another instance.\n      aproperty: null                   // this will set template.aproperty to\n                                        // null\n    }\n};\n```\n\n### merging template values ###\n\nMerging properties into templates means\n* inserting properties which did not yet exist\n* setting values to properties that do exist\n* deleting templates properties if value to merge is null\n* mering will iterate into object trees\n\n```javascript\nconst BUILD    = \"...some path\";\nconst jsonfile = {\n  target1: {\n    template: {                         // a template object\n      pname1:     5,\n      pname2:     true,\n      pname3:     { key: \"value\" },\n      aproperty:  \"a aproperty will be deleted\"\n    },\n    dest:     `${ BUILD }/file.json`,   // write the result to this file.\n    merge: {\n      pname3: { key: { test: \"fun\" }},  // this will replace value by { test: \"fun\" }\n      aproperty: undefined              // this will remove aproperty from template\n    }\n  }\n}\n\n```\n\n### updating template values ###\n\nUpdating template properties means\n* setting a value to a template property that exists\n* ignoring properties that do not exist in the template\n\n```javascript\nconst BUILD    = \"...some path\";\nconst jsonfile = {\n  target1: {\n    template: {                         // a template object\n      pname1:     5,\n      pname2:     true,\n      pname3:     { key: \"value\" },\n      aproperty:  \"a aproperty will be deleted\"\n    },\n    dest:     `${ BUILD }/file.json`,   // write the result to this file.\n    update: {\n      pname1:     \"fun\",                // will set template.pname1 to \"fun\"\n      xproperty:  \"uups\"                // will change nothing, because there is\n                                        // no xproperty in template.      \n    }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdb-developer%2Fgrunt-jsonfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdb-developer%2Fgrunt-jsonfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdb-developer%2Fgrunt-jsonfile/lists"}