{"id":18712887,"url":"https://github.com/mrsteele/json-truncate","last_synced_at":"2025-04-12T11:54:05.814Z","repository":{"id":48440135,"uuid":"57406657","full_name":"mrsteele/json-truncate","owner":"mrsteele","description":"A way to truncate a json object.","archived":false,"fork":false,"pushed_at":"2022-09-22T17:47:20.000Z","size":310,"stargazers_count":5,"open_issues_count":6,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T06:41:43.718Z","etag":null,"topics":["json"],"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/mrsteele.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-29T19:00:22.000Z","updated_at":"2023-08-12T12:37:40.000Z","dependencies_parsed_at":"2022-08-31T15:21:56.822Z","dependency_job_id":null,"html_url":"https://github.com/mrsteele/json-truncate","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/mrsteele%2Fjson-truncate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsteele%2Fjson-truncate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsteele%2Fjson-truncate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsteele%2Fjson-truncate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrsteele","download_url":"https://codeload.github.com/mrsteele/json-truncate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248565045,"owners_count":21125414,"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"],"created_at":"2024-11-07T12:44:13.915Z","updated_at":"2025-04-12T11:54:05.793Z","avatar_url":"https://github.com/mrsteele.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-truncate\n\nA way to truncate a json object. Useful for circular referenced objects.\n\n## Status\n\n[![npm](https://img.shields.io/npm/v/json-truncate.svg?maxAge=0\u0026style=flat)](https://www.npmjs.com/package/json-truncate)\n[![Main](https://github.com/mrsteele/json-truncate/actions/workflows/main.yml/badge.svg)](https://github.com/mrsteele/json-truncate/actions/workflows/main.yml)\n[![Dependency Status](https://david-dm.org/mrsteele/json-truncate.svg)](#)\n[![devDependency Status](https://david-dm.org/mrsteele/json-truncate/dev-status.svg)](https://david-dm.org/mrsteele/json-truncate#info=devDependencies)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![npm](https://img.shields.io/npm/l/json-truncate.svg?maxAge=0\u0026style=flat)](https://raw.githubusercontent.com/mrsteele/json-truncate/master/LICENSE)\n[![Greenkeeper badge](https://badges.greenkeeper.io/mrsteele/json-truncate.svg)](https://greenkeeper.io/)\n\n## About\n\nIf you need to write data to a file or output an object to an api endpoint that has circular references I recommend you give `json-truncate` a try.\n\nBy removing deeply nested data to maintain simple copies of the circular references you can keep most of the data you might be interested in.\n\n## Install\n\n```\nnpm install json-truncate --save\n```\n\n## Usage\n\nBelow are examples of how to use `json-truncate`\n\n#### Including\n\nYou can include with regular node require:\n\n```javascript\nJSON.truncate = require('json-truncate')\n```\n\n#### Usage\n\n**Figure 1.0** - A basic example with default options.\n\n```javascript\nJSON.truncate(SomeDeepObject)\n```\n\n**Figure 1.1** - An example of setting the `maxDepth` property.\n\n```javascript\nJSON.truncate(SomeDeepObject, 5)\n```\n\n**Figure 1.2** - An example of all configurable options.\n\n```javascript\nconsole.log(JSON.truncate({\n  data: 'foo',\n  level1: {\n    data: 'bar',\n    level2: {\n      level3: {}\n    }\n  }\n}, {\n  maxDepth: 2,\n  replace: '[Truncated]'\n}))\n/**\n * Output:\n{\n  \"data\": \"foo\",\n  \"level1\": {\n    \"data\": \"bar\",\n    \"level2\": \"[Truncated]\"\n  }\n}\n **/\n```\n\n### Configuration\n\nBy default, there are two configurable variables to keep in mind when using `json-truncate`:\n\n1. `maxDepth (Number)` = `10`\n2. `replace (Any)` = `undefined`\n\nIf you would you can configure these either individually with each request, or globally with the configuration function. The following example mimics figure 1.2 above.\n\n```javascript\nJSON.truncate.configure({\n  maxDepth: 2,\n  replace: '[Truncated]'\n})\n```\n\n#### Arguments\n\n* `obj` - The Object that will be truncated.\n* `options` - (optional) An option object to customize the behavior of the utility. Defaults to `{}`.\n\n**Current Option Properties**\n\n|Option|Description|\n|:--|:--|\n|**maxDepth**|The default maxDepth to use for nested and deep properties on an object. Defaults to `10`|\n|:--|:--|\n|**replace**|A string value that is used to replace all truncated values. If this value is not a string then all truncated values will be replaced with `undefined`|\n\n\n## Licence\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrsteele%2Fjson-truncate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrsteele%2Fjson-truncate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrsteele%2Fjson-truncate/lists"}