{"id":28203871,"url":"https://github.com/riologiuseppe/json2json-transformer","last_synced_at":"2026-04-15T20:03:05.717Z","repository":{"id":57285536,"uuid":"119561204","full_name":"RioloGiuseppe/json2json-transformer","owner":"RioloGiuseppe","description":"Simple library to transform json documents using json templates","archived":false,"fork":false,"pushed_at":"2018-06-27T10:04:16.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T14:06:44.927Z","etag":null,"topics":["json","rendering","template","templating","transforming-json"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RioloGiuseppe.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-30T16:15:37.000Z","updated_at":"2021-09-21T23:02:56.000Z","dependencies_parsed_at":"2022-08-24T16:41:15.765Z","dependency_job_id":null,"html_url":"https://github.com/RioloGiuseppe/json2json-transformer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RioloGiuseppe%2Fjson2json-transformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RioloGiuseppe%2Fjson2json-transformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RioloGiuseppe%2Fjson2json-transformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RioloGiuseppe%2Fjson2json-transformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RioloGiuseppe","download_url":"https://codeload.github.com/RioloGiuseppe/json2json-transformer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RioloGiuseppe%2Fjson2json-transformer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259092684,"owners_count":22804061,"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":["json","rendering","template","templating","transforming-json"],"created_at":"2025-05-17T03:15:24.366Z","updated_at":"2026-04-15T20:03:05.665Z","avatar_url":"https://github.com/RioloGiuseppe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json2json-transformer\nTransform a generic object using JSONPath. \u003cbr/\u003e\u003cbr/\u003e\n\nPulls data from a data object using JSONPath and generate a new objects based on a template. Each of the template's properties can pull properties from the source data or an array of all results found by its JSONPath. When pulling an array of data you can also supply a subtemplate to transform each item in the array.\n\n## Import\nImport in your project using\n```sh\nnpm i --s json2json-transformer\n```\n## Usage\nImport reference in javascript\n```js\nconst render = require('json2json-transformer');\n```\n\nImport reference in typescript\n```ts\nimport * as render from 'json2json-transformer'\n```\n\nDefine a template \n\n```js\nlet template = {\n    literalProperty: \"Constant\",                                                                        // Constant string in template\n    simpleProperty : \"'$.propertyDemo1'\",                                                               // Dynamic property (first level in data obj)\n    composeProperty : \"Two strings '$.propertyDemo1''$.propertyDemo2' and a number '$.mumberValue'\",    // Computed propery thet mix strings and number\n    deepProperty : \"'$.complexObject.nestedProperty'\",                                                  // Dynamic property (second level in data obj)\n    complexObject : {                                                                                   // Complex object in template\n        nestedProperty: \"'$.data2' valorized with other data\"                                           // This property is not present in first data obj\n    },\n    arrayProperty: [                                                                                    // Static array defined in template\n        \"literal in array\",                                                                             // Static literal string in array\n        \"'$.stringInArray'\",                                                                            // Dynamic string in array\n        {                                                                                               \n            ObjectInArray: \"'$.inArray'\"                                                                // Dynamic property inside an object in array\n        }\n    ],\n    \"'$..values'\":                                                                                      // Dynamic array in template, path in data source\n    [\"repeatedTemplate\",                                                                                // Property name in destination object\n    {                                                                                                   // Array item template\n        repeatedSimpleProp:\"'$.val'\"\n    }]\n}\n```\n\nDefine object data\n```js\nvar data1 = {\n    propertyDemo1: \"some value\",\n    propertyDemo2: \"other value\",\n    complexObject: {\n        nestedProperty: \"deep\"\n    },\n    inArray: \"Inside an object in array!\",\n    stringInArray: \"Inside an object in array!\",\n    mumberValue:5000,\n}\n\nvar data2 = {\n    data2: \"more data\",\n    values:[{\n        val: 0\n    }]\n}\n```\n\nApply template\n\n```js\n// Apply data1 at template object. All un matched properties will be ignored\nlet step1 = render.parseTemplate(data1, template, true);\n\n// Apply data2 at step1 output. All un matched properties will be ignored\nlet step2 = render.parseTemplate(data2, step1, true);\n\n// Print output in console\nconsole.log(\"template\",JSON.stringify(template,null,2));\nconsole.log(\"step1\",JSON.stringify(step1,null,2));\nconsole.log(\"step2\",JSON.stringify(step2,null,2));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friologiuseppe%2Fjson2json-transformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friologiuseppe%2Fjson2json-transformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friologiuseppe%2Fjson2json-transformer/lists"}