{"id":15284256,"url":"https://github.com/rubeniskov/mutant-json","last_synced_at":"2026-01-05T16:04:56.378Z","repository":{"id":57305699,"uuid":"315729462","full_name":"rubeniskov/mutant-json","owner":"rubeniskov","description":"A complete mutate json function which traverses using traverse-json.","archived":false,"fork":false,"pushed_at":"2020-12-08T15:53:45.000Z","size":143,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T19:51:11.643Z","etag":null,"topics":["iteratee","iterator","json","jsonpatch","jsonpatch-standard","jsonschema","mutation","patch","promises","redux","state","traverse","traverse-json"],"latest_commit_sha":null,"homepage":"http://rubeniskov.com/blog/en/traverse-json-like-a-king","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/rubeniskov.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":"2020-11-24T19:13:45.000Z","updated_at":"2022-07-27T23:57:07.000Z","dependencies_parsed_at":"2022-09-01T09:21:48.414Z","dependency_job_id":null,"html_url":"https://github.com/rubeniskov/mutant-json","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubeniskov%2Fmutant-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubeniskov%2Fmutant-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubeniskov%2Fmutant-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubeniskov%2Fmutant-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubeniskov","download_url":"https://codeload.github.com/rubeniskov/mutant-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245138226,"owners_count":20566892,"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":["iteratee","iterator","json","jsonpatch","jsonpatch-standard","jsonschema","mutation","patch","promises","redux","state","traverse","traverse-json"],"created_at":"2024-09-30T14:52:06.344Z","updated_at":"2026-01-05T16:04:56.270Z","avatar_url":"https://github.com/rubeniskov.png","language":"JavaScript","funding_links":["https://patreon.com/rubeniskov","https://github.com/sponsors/rubeniskov","https://paypal.me/rubeniskov"],"categories":[],"sub_categories":[],"readme":"# mutant-json\n\n[![unit-testing](https://github.com/rubeniskov/mutant-json/workflows/unit-testing/badge.svg)](https://github.com/rubeniskov/mutant-json/actions?query=workflow%3Aunit-testing)\n[![npm-publish](https://github.com/rubeniskov/mutant-json/workflows/npm-publish/badge.svg)](https://github.com/rubeniskov/mutant-json/actions?query=workflow%3Anpm-publish)\n[![npm-downloads](https://img.shields.io/npm/dw/mutant-json)](https://www.npmjs.com/package/mutant-json)\n[![codecov](https://codecov.io/gh/rubeniskov/mutant-json/branch/master/graph/badge.svg)](https://codecov.io/gh/rubeniskov/mutant-json)\n[![patreon-donate](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://patreon.com/rubeniskov)\n[![github-sponsor](https://img.shields.io/badge/github-donate-yellow.svg)](https://github.com/sponsors/rubeniskov)\n[![paypal-sponsor](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://paypal.me/rubeniskov)\n\nA complete mutant json which uses [traverse-json](https://github.com/rubeniskov/traverse-json) to enable traverse filtering.\n\n## Motivation\n\nMany time I've encontered with the difficult task of mutate a object with nested properties by filtering properties using a single function, so a `mutant-json` solves this using `traverse-json` with multiple options for traversing.\n\n\n## Installation\n\n### Npm:\n```shell\nnpm install mutant-json --save\n```\n### Yarn:\n```shell\nyarn add mutant-json\n```\n## Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#mutantJson\"\u003emutantJson(target, process, opts)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eIterates through the given iterator and applies mutation\nwhereas the iterator entry returns. Also works with promises.\nThe iteratee must return an entry of [path, value].\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n## Typedefs\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#MutanPatch\"\u003eMutanPatch\u003c/a\u003e : \u003ccode\u003efunction\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003ePatch definition acording to the \u003ca href=\"http://jsonpatch.com/\"\u003ejsonpatch standard\u003c/a\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#MutantPatcher\"\u003eMutantPatcher\u003c/a\u003e : \u003ccode\u003efunction\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#MutantProcess\"\u003eMutantProcess\u003c/a\u003e : \u003ccode\u003efunction\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#MutantJsonEntry\"\u003eMutantJsonEntry\u003c/a\u003e : \u003ccode\u003eArray\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#MutantOptions\"\u003eMutantOptions\u003c/a\u003e : \u003ccode\u003eObject\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"mutantJson\"\u003e\u003c/a\u003e\n\n## mutantJson(target, process, opts)\nIterates through the given iterator and applies mutation\nwhereas the iterator entry returns. Also works with promises.\nThe iteratee must return an entry of [path, value].\n\n**Kind**: global function  \n\n| Param | Type |\n| --- | --- |\n| target | \u003ccode\u003eany\u003c/code\u003e | \n| process | [\u003ccode\u003eMutantProcess\u003c/code\u003e](#MutantProcess) | \n| opts | [\u003ccode\u003eMutantOptions\u003c/code\u003e](#MutantOptions) | \n\n**Example**  \n### Working with promises\n\n```javascript\nconst mutateJson = require('mutant-json');\n\nconst recursiveObjectPromises = {\n  foo: 0,\n  nested: Promise.resolve({\n    depth: 1,\n    nested: Promise.resolve({\n      depth: 2,\n      nested: Promise.resolve({\n        depth: 3,\n        nested: Promise.resolve({\n          depth: 4,\n        }),\n      }),\n    }),\n  }),\n  bar: 1,\n};\n\nconst actual = await mutateJson(recursiveObjectPromises, (mutate, value) =\u003e {\n  mutate({\n    value: value * 2,\n  });\n});\n\nconsole.log(actual);\n```\n\n### Output\n```\n{\n  foo: 0,\n  nested: {\n    depth: 2,\n    nested: {\n      depth: 4,\n      nested: {\n        depth: 6,\n        nested: {\n          depth: 8,\n        },\n      },\n    },\n  },\n  bar: 2,\n}\n```\n\u003ca name=\"MutanPatch\"\u003e\u003c/a\u003e\n\n## MutanPatch : \u003ccode\u003efunction\u003c/code\u003e\nPatch definition acording to the [jsonpatch standard](http://jsonpatch.com/)\n\n**Kind**: global typedef  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| op | \u003ccode\u003e\u0026quot;remove\u0026quot;\u003c/code\u003e \\| \u003ccode\u003e\u0026quot;replace\u0026quot;\u003c/code\u003e | Patch operation |\n| value | \u003ccode\u003eany\u003c/code\u003e |  |\n\n\u003ca name=\"MutantPatcher\"\u003e\u003c/a\u003e\n\n## MutantPatcher : \u003ccode\u003efunction\u003c/code\u003e\n**Kind**: global typedef  \n\n| Param | Type |\n| --- | --- |\n| patches | [\u003ccode\u003eMutanPatch\u003c/code\u003e](#MutanPatch) \\| [\u003ccode\u003eArray.\u0026lt;MutanPatch\u0026gt;\u003c/code\u003e](#MutanPatch) | \n\n\u003ca name=\"MutantProcess\"\u003e\u003c/a\u003e\n\n## MutantProcess : \u003ccode\u003efunction\u003c/code\u003e\n**Kind**: global typedef  \n\n| Param | Type |\n| --- | --- |\n| mutate | \u003ccode\u003eMutationPatcher\u003c/code\u003e | \n| value | \u003ccode\u003eany\u003c/code\u003e | \n| path | \u003ccode\u003estring\u003c/code\u003e | \n| result | \u003ccode\u003eany\u003c/code\u003e | \n\n\u003ca name=\"MutantJsonEntry\"\u003e\u003c/a\u003e\n\n## MutantJsonEntry : \u003ccode\u003eArray\u003c/code\u003e\n**Kind**: global typedef  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| 0 | \u003ccode\u003estring\u003c/code\u003e | [JSONPointer](https://tools.ietf.org/html/rfc6901) |\n| 1 | \u003ccode\u003eany\u003c/code\u003e | Value |\n\n\u003ca name=\"MutantOptions\"\u003e\u003c/a\u003e\n\n## MutantOptions : \u003ccode\u003eObject\u003c/code\u003e\n**Kind**: global typedef  \n**Properties**\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| [recursive] | \u003ccode\u003eBoolean\u003c/code\u003e | \u003ccode\u003etrue\u003c/code\u003e | enable/disable nested arrays and objects recursion |\n| [nested] | \u003ccode\u003eBoolean\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | also emit nested array or objects |\n| [step] | \u003ccode\u003eBoolean\u003c/code\u003e | \u003ccode\u003e1\u003c/code\u003e | the step to increment, default 1 |\n| [test] | \u003ccode\u003eString\u003c/code\u003e \\| \u003ccode\u003efunction\u003c/code\u003e \\| \u003ccode\u003eRegeExp\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | regexp, string [minimatch](https://www.npmjs.com/package/minimatch) or function to filter properties |\n| [once] | \u003ccode\u003eBoolean\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | Stops when applies the first mutation |\n| [promises] | \u003ccode\u003eBoolean\u003c/code\u003e | \u003ccode\u003etrue\u003c/code\u003e | Processing promises taking the resolved as part of the result |\n| [promise] | \u003ccode\u003eBoolean\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | Forces to return a promise even if no promises detected |\n| [iterator] | \u003ccode\u003eArray.\u0026lt;MutationJsonEntry\u0026gt;\u003c/code\u003e \\| \u003ccode\u003eIterable\u003c/code\u003e \\| \u003ccode\u003eIterator\u003c/code\u003e |  | Iterator default [traverse-json](https://github.com/rubeniskov/traverse-json) |\n| [patcher] | \u003ccode\u003efunction\u003c/code\u003e |  | Patcher function |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubeniskov%2Fmutant-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubeniskov%2Fmutant-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubeniskov%2Fmutant-json/lists"}