{"id":28311048,"url":"https://github.com/vaibhavacharya/json-mason","last_synced_at":"2026-05-15T18:03:36.784Z","repository":{"id":264267806,"uuid":"892263816","full_name":"VaibhavAcharya/json-mason","owner":"VaibhavAcharya","description":"A library for performing structured modifications on JSON data. It provides a safe, predictable way to transform JSON objects through a series of operations.","archived":false,"fork":false,"pushed_at":"2024-11-21T19:52:12.000Z","size":12,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-05T23:56:14.888Z","etag":null,"topics":["data-manipulation","json","json-manipulation","json-operations","json-transformation"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/json-mason","language":"TypeScript","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/VaibhavAcharya.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-21T19:43:51.000Z","updated_at":"2025-04-02T20:38:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"c64f5372-9f9e-43af-95f4-4c5b88f29070","html_url":"https://github.com/VaibhavAcharya/json-mason","commit_stats":null,"previous_names":["vaibhavacharya/json-mason"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/VaibhavAcharya/json-mason","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaibhavAcharya%2Fjson-mason","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaibhavAcharya%2Fjson-mason/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaibhavAcharya%2Fjson-mason/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaibhavAcharya%2Fjson-mason/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VaibhavAcharya","download_url":"https://codeload.github.com/VaibhavAcharya/json-mason/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaibhavAcharya%2Fjson-mason/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280901420,"owners_count":26410586,"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","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"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":["data-manipulation","json","json-manipulation","json-operations","json-transformation"],"created_at":"2025-05-24T12:10:26.141Z","updated_at":"2026-05-15T18:03:36.761Z","avatar_url":"https://github.com/VaibhavAcharya.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-mason\n\n[![npm version](https://badge.fury.io/js/json-mason.svg)](https://www.npmjs.com/package/json-mason)\n[![tests passing: 33/33](https://img.shields.io/badge/tests%20passing-26/26-blue.svg)](https://github.com/VaibhavAcharya/json-mason/blob/main/tests/index.ts)\n\nJson Mason is a library for performing structured modifications on JSON data. It provides a safe, predictable way to transform JSON objects through a series of operations.\n\nIt is light-weight, dependency-free, type-safe yet feature-full.\n\n## Features\n\n- Structured JSON modifications\n- Path-based targeting\n- Array and string manipulations\n- Deep cloning of data\n- Comprehensive error handling\n- Type-safe operations\n\n## Installation\n\n```bash\nnpm install json-mason\n\n# or\nyarn add json-mason\npnpm add json-mason\nbun add json-mason\n```\n\n## Quick Start\n\n```typescript\nimport { JsonMason } from 'json-mason';\n\nconst mason = new JsonMason();\n\nconst data = {\n  user: {\n    name: \"John\",\n    tags: [\"user\"]\n  }\n};\n\nconst operations = [\n  { path: [\"user\", \"name\"], action: \"set\", value: \"John Smith\" },\n  { path: [\"user\", \"tags\"], action: \"append\", value: \"admin\" }\n];\n\nconst result = mason.apply(data, operations);\n// Result:\n// {\n//   user: {\n//     name: \"John Smith\",\n//     tags: [\"user\", \"admin\"]\n//   }\n// }\n```\n\n## API Reference\n\n### JsonMason Class\n\n#### `apply\u003cT\u003e(source: T, operations: Operation[], config?: Config): T`\n\nApplies a series of operations to a source object.\n\n```typescript\nconst mason = new JsonMason();\n\n// Single operation\nconst result1 = mason.apply(data, [\n  { path: [\"user\", \"name\"], action: \"set\", value: \"John\" }\n]);\n\n// Multiple operations\nconst result2 = mason.apply(data, [\n  { path: [\"users\"], action: \"set\", value: [] },\n  { path: [\"users\"], action: \"append\", value: { id: 1 }}\n]);\n\n// With config\nconst result3 = mason.apply(data, operations, { strict: false });\n```\n\n#### `getErrors(): OperationError[]`\n\nRetrieves errors from the last operation (when strict mode is disabled).\n\n```typescript\nconst mason = new JsonMason();\nmason.apply(data, operations, { strict: false });\nconst errors = mason.getErrors();\n// [{index: 0, operation: {...}, reason: \"...\"}]\n```\n\n### Supported Operations\n\n#### Set Operation\nSets a value at a specific path.\n\n```typescript\nconst operation = {\n  path: [\"user\", \"settings\", \"theme\"],\n  action: \"set\",\n  value: \"dark\"\n};\n```\n\n#### Append Operation\nAppends a value to an array or string.\n\n```typescript\n// Array append\nconst arrayOp = {\n  path: [\"tags\"],\n  action: \"append\",\n  value: \"new-tag\"\n};\n\n// String append\nconst stringOp = {\n  path: [\"message\"],\n  action: \"append\",\n  value: \" World\"\n};\n```\n\n#### Prepend Operation\nPrepends a value to an array or string.\n\n```typescript\n// Array prepend\nconst arrayOp = {\n  path: [\"tags\"],\n  action: \"prepend\",\n  value: \"important\"\n};\n\n// String prepend\nconst stringOp = {\n  path: [\"message\"],\n  action: \"prepend\",\n  value: \"Hello \"\n};\n```\n\n#### Delete Operation\nRemoves a value at a specific path.\n\n```typescript\nconst operation = {\n  path: [\"user\", \"temporary\"],\n  action: \"delete\"\n};\n```\n\n### Configuration\n\nYou can configure JsonMason behavior using the Config object:\n\n```typescript\ninterface Config {\n  strict?: boolean; // When true, throws errors immediately. Default: true\n}\n```\n\nExample:\n```typescript\n// Throw immediately on error (default)\nconst result = mason.apply(data, operations, { strict: true });\n\n// Continue on errors\nconst result = mason.apply(data, operations, { strict: false });\n```\n\n## Error Handling\n\nJsonMason provides detailed error information when operations fail:\n\n```typescript\ntry {\n  mason.apply(data, operations);\n} catch (error) {\n  console.error(error.message);\n}\n\n// Or in non-strict mode:\nmason.apply(data, operations, { strict: false });\n\nconst errors = mason.getErrors();\n\nerrors.forEach(error =\u003e {\n  console.log(`Operation ${error.index} failed: ${error.reason}`);\n});\n```\n\n## Type Safety\n\nJsonMason is written in TypeScript and provides full type safety:\n\n```typescript\nimport { Operation } from 'json-mason';\n\n// Type-checked operations\nconst operation: Operation = {\n  path: [\"users\", 0, \"name\"],\n  action: \"set\",\n  value: \"John\"\n};\n```\n\n## License\n\nMIT\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaibhavacharya%2Fjson-mason","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaibhavacharya%2Fjson-mason","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaibhavacharya%2Fjson-mason/lists"}