{"id":22484926,"url":"https://github.com/maxlath/json-apply","last_synced_at":"2026-06-10T15:31:16.255Z","repository":{"id":151861560,"uuid":"624980700","full_name":"maxlath/json-apply","owner":"maxlath","description":"A CLI tool to transform JSON files with custom JS functions","archived":false,"fork":false,"pushed_at":"2026-02-20T12:46:14.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-20T16:51:57.108Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/maxlath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"liberapay":"Association_Inventaire"}},"created_at":"2023-04-07T18:45:26.000Z","updated_at":"2026-02-20T12:46:17.000Z","dependencies_parsed_at":"2023-05-13T02:30:37.689Z","dependency_job_id":null,"html_url":"https://github.com/maxlath/json-apply","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maxlath/json-apply","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fjson-apply","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fjson-apply/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fjson-apply/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fjson-apply/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxlath","download_url":"https://codeload.github.com/maxlath/json-apply/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fjson-apply/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34159249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-12-06T17:11:45.604Z","updated_at":"2026-06-10T15:31:16.239Z","avatar_url":"https://github.com/maxlath.png","language":"JavaScript","funding_links":["https://liberapay.com/Association_Inventaire"],"categories":["JavaScript"],"sub_categories":[],"readme":"# json-apply\nA CLI tool to transform JSON files with custom JS functions\n\nFeatures:\n* take the JS function to apply from a file\n* the function may return async results\n* preview the transformation results with the `--diff` option\n\n[![NPM](https://nodei.co/npm/json-apply.png?stars\u0026downloads\u0026downloadRank)](https://npmjs.com/package/json-apply/)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Node](https://img.shields.io/badge/node-%3E=%20v7.6.0-brightgreen.svg)](http://nodejs.org)\n\n\n## Summary\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Install](#install)\n- [How To](#how-to)\n  - [Basic](#basic)\n  - [Async](#async)\n  - [Diff mode](#diff-mode)\n  - [Use sub-function](#use-sub-function)\n- [See also](#see-also)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n\n## Install\n```sh\nnpm install --global json-apply\n```\n\n## How To\n\n### Basic\n```sh\n# Transform one json file at a time\njson-apply some_transform_function.js some_data.json \u003e some_data_transformed.json\n# Transform many json files\njson-apply -i some_transform_function.js *.json\n```\nwhere `some_transform_function.js` just needs to export a JS function. This should work both with the ESM export syntax\n```js\n// some_transform_function.js\nexport default function (doc) {\n  doc.total = doc.a + doc.b\n  if (doc.total % 2 === 0) {\n    return doc\n  } else {\n    // returning null or undefined drops the entry\n  }\n}\n```\nor with the CommonJS export syntax\n```js\n// some_transform_function.js\nmodule.exports = function (doc) {\n  doc.total = doc.a + doc.b\n  if (doc.total % 2 === 0) {\n    return doc\n  } else {\n    // returning null or undefined drops the entry\n  }\n}\n```\n\n### Async\nThat function can also be async:\n```js\nimport { getSomeExtraData } from './path/to/get_some_extra_data.js'\n\n// some_async_transform_function.js\nexport default async function (doc) {\n  doc.total = doc.a + doc.b\n  if (doc.total % 2 === 0) {\n    doc.extraData = await getSomeExtraData(doc)\n    return doc\n  } else {\n    // returning null or undefined drops the entry\n  }\n}\n```\n\n### Diff mode\nAs a way to preview the results of your transformation, you can use the diff mode\n```sh\njson-apply some_transform_function.js some_data.json --diff\n```\nwhich will display a colored diff of each line before and after transformation.\n\nFor more readability, each line diff output is indented and on several lines.\n\n### Use sub-function\nGiven a `function_collection.js` file like:\n```js\n// function_collection.js\nexport function foo (obj) {\n  obj.timestamp = Date.now()\n  return obj\n}\n\nexport function bar (obj) {\n  obj.count += obj.count\n  return obj\n}\n```\n\nYou can use those subfunction by passing their key as an additional argument\n```sh\njson-apply function_collection.js#foo some_data.json\njson-apply function_collection.js#bar some_data.json\n```\n\nThis should also work with the CommonJS syntax:\n```js\n// function_collection.cjs\nmodule.exports = {\n  foo: (obj) =\u003e {\n    obj.timestamp = Date.now()\n    return obj\n  },\n  bar: (obj) =\u003e {\n    obj.count += obj.count\n    return obj\n  }\n}\n```\n\n## See also\n* [jq](https://stedolan.github.io/jq/)\n* [ndjson-apply](https://github.com/maxlath/ndjson-apply/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxlath%2Fjson-apply","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxlath%2Fjson-apply","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxlath%2Fjson-apply/lists"}