{"_id":"@cjser/flatted","name":"@cjser/flatted","dist-tags":{"latest":"3.4.2-cjser.2"},"versions":{"3.4.2-cjser.2":{"name":"@cjser/flatted","version":"3.4.2-cjser.2","description":"A super light and fast circular JSON parser.","unpkg":"min.js","main":"./dist-cjser/index.cjs","scripts":{"build":"npm run cjs && npm run rollup:esm && npm run rollup:es && npm run rollup:babel && npm run min && npm run test && npm run size","cjs":"ascjs esm cjs","rollup:es":"rollup --config rollup/es.config.js && sed -i.bck 's/^var /self./' es.js && rm -rf es.js.bck","rollup:esm":"rollup --config rollup/esm.config.js","rollup:babel":"rollup --config rollup/babel.config.js && sed -i.bck 's/^var /self./' index.js && rm -rf index.js.bck","min":"terser index.js -c -m -o min.js","size":"cat index.js | wc -c;cat min.js | wc -c;gzip -c9 min.js | wc -c;cat min.js | brotli | wc -c; cat es.js | brotli | wc -c; cat esm.js | brotli | wc -c","test":"c8 node test/index.js","test:php":"php php/test.php","test:py":"python python/test.py","ts":"tsc -p .","coverage":"mkdir -p ./coverage; c8 report --reporter=text-lcov > ./coverage/lcov.info"},"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"keywords":["circular","JSON","fast","parser","minimal"],"author":{"name":"Andrea Giammarchi"},"license":"ISC","bugs":{"url":"https://github.com/WebReflection/flatted/issues"},"homepage":"https://github.com/WebReflection/flatted#readme","devDependencies":{"@babel/core":"^7.29.0","@babel/preset-env":"^7.29.0","@rollup/plugin-babel":"^7.0.0","@rollup/plugin-terser":"^1.0.0","@ungap/structured-clone":"^1.3.0","ascjs":"^6.0.3","c8":"^11.0.0","circular-json":"^0.5.9","circular-json-es6":"^2.0.2","flatted-view":"^0.1.1","jsan":"^3.1.14","rollup":"^4.59.0","terser":"^5.46.0","typescript":"^5.9.3"},"module":"./esm/index.js","type":"module","exports":{".":{"types":"./types/index.d.ts","require":"./dist-cjser/index.cjs","import":"./esm/index.js","default":"./cjs/index.js"},"./esm":{"require":"./dist-cjser/esm.cjs","default":"./esm.js"},"./package.json":"./package.json"},"types":"./types/index.d.ts","cjser":{"sourceVersion":"3.4.2","cjserVersion":2,"original":{"name":"flatted","version":"3.4.2","main":"./cjs/index.js","exports":{".":{"types":"./types/index.d.ts","import":"./esm/index.js","default":"./cjs/index.js"},"./esm":"./esm.js","./package.json":"./package.json"},"repository":{"type":"git","url":"git+https://github.com/WebReflection/flatted.git"},"files":["LICENSE","README.md","cjs/","es.js","esm.js","esm/","index.js","min.js","php/flatted.php","python/flatted.py","golang/pkg/flatted/flatted.go","types/"],"scripts":{"build":"npm run cjs && npm run rollup:esm && npm run rollup:es && npm run rollup:babel && npm run min && npm run test && npm run size","cjs":"ascjs esm cjs","rollup:es":"rollup --config rollup/es.config.js && sed -i.bck 's/^var /self./' es.js && rm -rf es.js.bck","rollup:esm":"rollup --config rollup/esm.config.js","rollup:babel":"rollup --config rollup/babel.config.js && sed -i.bck 's/^var /self./' index.js && rm -rf index.js.bck","min":"terser index.js -c -m -o min.js","size":"cat index.js | wc -c;cat min.js | wc -c;gzip -c9 min.js | wc -c;cat min.js | brotli | wc -c; cat es.js | brotli | wc -c; cat esm.js | brotli | wc -c","test":"c8 node test/index.js","test:php":"php php/test.php","test:py":"python python/test.py","ts":"tsc -p .","coverage":"mkdir -p ./coverage; c8 report --reporter=text-lcov > ./coverage/lcov.info"}}},"_id":"@cjser/flatted@3.4.2-cjser.2","gitHead":"0168e4aac54a1a9ca6f921419fa5ed9edb53ef4a","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-y+PKwwysxg1RSwIOmisVO7CNWXQHsSaA4ISRNjrWunyYH/Rh4AwrR9fWw+qeeOnVsk/efVxWaD6T0C0UDL3YVg==","shasum":"277085b44056445d136af412c5bad7b4cd16374c","tarball":"https://registry.npmjs.org/@cjser/flatted/-/flatted-3.4.2-cjser.2.tgz","fileCount":17,"unpackedSize":47340,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHnzyh+C/+OmZsOwlcv/xO4PBRnT3wvXzAM6LlJhWvqKAiEAyZpjlRX3htaQtVgi7n11Ifys28PG4phtOsxQhPj6OAo="}]},"_npmUser":{"name":"nanahira","email":"nanahira@momobako.com"},"directories":{},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/flatted_3.4.2-cjser.2_1778130570212_0.15448822801126783"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-07T05:09:30.128Z","3.4.2-cjser.2":"2026-05-07T05:09:30.361Z","modified":"2026-05-07T05:09:30.585Z"},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"description":"A super light and fast circular JSON parser.","homepage":"https://github.com/WebReflection/flatted#readme","keywords":["circular","JSON","fast","parser","minimal"],"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"author":{"name":"Andrea Giammarchi"},"bugs":{"url":"https://github.com/WebReflection/flatted/issues"},"license":"ISC","readme":"# flatted\n\n[![Downloads](https://img.shields.io/npm/dm/flatted.svg)](https://www.npmjs.com/package/flatted) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/flatted/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/flatted?branch=main) [![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC) ![WebReflection status](https://offline.report/status/webreflection.svg)\n\n![snow flake](./flatted.jpg)\n\n<sup>**Social Media Photo by [Matt Seymour](https://unsplash.com/@mattseymour) on [Unsplash](https://unsplash.com/)**</sup>\n\nA super light (0.5K) and fast circular JSON parser, directly from the creator of [CircularJSON](https://github.com/WebReflection/circular-json/#circularjson).\n\nAvailable also for **[PHP](./php/flatted.php)**.\n\nAvailable also for **[Python](./python/flatted.py)**.\n\nAvailable also for **[Go](./golang/README.md)**.\n\n- - -\n\n## ℹ️ JSON only values\n\nIf you need anything more complex than values JSON understands, there is a standard approach to recursion and more data-types than what JSON allows, and it's part of the [Structured Clone polyfill](https://github.com/ungap/structured-clone/#readme).\n\n- - -\n\n```js\nnpm i flatted\n```\n\nUsable via [CDN](https://unpkg.com/flatted) or as regular module.\n\n```js\n// ESM\nimport {parse, stringify, toJSON, fromJSON} from 'flatted';\n\n// CJS\nconst {parse, stringify, toJSON, fromJSON} = require('flatted');\n\nconst a = [{}];\na[0].a = a;\na.push(a);\n\nstringify(a); // [[\"1\",\"0\"],{\"a\":\"0\"}]\n```\n\n## toJSON and fromJSON\n\nIf you'd like to implicitly survive JSON serialization, these two helpers helps:\n\n```js\nimport {toJSON, fromJSON} from 'flatted';\n\nclass RecursiveMap extends Map {\n  static fromJSON(any) {\n    return new this(fromJSON(any));\n  }\n  toJSON() {\n    return toJSON([...this.entries()]);\n  }\n}\n\nconst recursive = new RecursiveMap;\nconst same = {};\nsame.same = same;\nrecursive.set('same', same);\n\nconst asString = JSON.stringify(recursive);\nconst asMap = RecursiveMap.fromJSON(JSON.parse(asString));\nasMap.get('same') === asMap.get('same').same;\n// true\n```\n\n\n## Flatted VS JSON\n\nAs it is for every other specialized format capable of serializing and deserializing circular data, you should never `JSON.parse(Flatted.stringify(data))`, and you should never `Flatted.parse(JSON.stringify(data))`.\n\nThe only way this could work is to `Flatted.parse(Flatted.stringify(data))`, as it is also for _CircularJSON_ or any other, otherwise there's no granted data integrity.\n\nAlso please note this project serializes and deserializes only data compatible with JSON, so that sockets, or anything else with internal classes different from those allowed by JSON standard, won't be serialized and unserialized as expected.\n\n\n### New in V1: Exact same JSON API\n\n  * Added a [reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Syntax) parameter to `.parse(string, reviver)` and revive your own objects.\n  * Added a [replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Syntax) and a `space` parameter to `.stringify(object, replacer, space)` for feature parity with JSON signature.\n\n\n### Compatibility\nAll ECMAScript engines compatible with `Map`, `Set`, `Object.keys`, and `Array.prototype.reduce` will work, even if polyfilled.\n\n\n### How does it work ?\nWhile stringifying, all Objects, including Arrays, and strings, are flattened out and replaced as unique index. `*`\n\nOnce parsed, all indexes will be replaced through the flattened collection.\n\n<sup><sub>`*` represented as string to avoid conflicts with numbers</sub></sup>\n\n```js\n// logic example\nvar a = [{one: 1}, {two: '2'}];\na[0].a = a;\n// a is the main object, will be at index '0'\n// {one: 1} is the second object, index '1'\n// {two: '2'} the third, in '2', and it has a string\n// which will be found at index '3'\n\nFlatted.stringify(a);\n// [[\"1\",\"2\"],{\"one\":1,\"a\":\"0\"},{\"two\":\"3\"},\"2\"]\n// a[one,two]    {one: 1, a}    {two: '2'}  '2'\n```\n\n## cjser\n\nThis package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.\nOriginal repository: https://github.com/WebReflection/flatted\n","readmeFilename":"README.md","_rev":"1-518f347cb9ef3e231d410a12f30189f2"}