Gathering detailed insights and metrics for flatted
Gathering detailed insights and metrics for flatted
Gathering detailed insights and metrics for flatted
Gathering detailed insights and metrics for flatted
flatted-object
Module to flatten objects like a pro, with guarantees to avoid losing data in the process.
@ndelangen/flatted
A super light and fast circular JSON parser.
deepbase
⚡ Fastest and simplest way to add persistence to your projects.
superserial
A comprehensive Serializer/Deserializer that can handle any data type.
npm install flatted
Typescript
Module System
Node Version
NPM Version
99.7
Supply Chain
100
Quality
77.9
Maintenance
100
Vulnerability
100
License
JavaScript (66.3%)
PHP (19.39%)
Python (13.38%)
HTML (0.93%)
Total Downloads
7,349,303,298
Last Day
3,155,855
Last Week
51,313,024
Last Month
221,744,847
Last Year
2,158,237,311
ISC License
1,095 Stars
141 Commits
50 Forks
9 Watchers
5 Branches
10 Contributors
Updated on Jun 30, 2025
Minified
Minified + Gzipped
Latest Version
3.3.3
Package Id
flatted@3.3.3
Unpacked Size
30.79 kB
Size
8.80 kB
File Count
13
NPM Version
11.1.0
Node Version
23.8.0
Published on
Feb 18, 2025
Cumulative downloads
Total Downloads
Last Day
-12.6%
3,155,855
Compared to previous day
Last Week
-8.9%
51,313,024
Compared to previous week
Last Month
2.3%
221,744,847
Compared to previous month
Last Year
28.2%
2,158,237,311
Compared to previous year
Social Media Photo by Matt Seymour on Unsplash
A super light (0.5K) and fast circular JSON parser, directly from the creator of CircularJSON.
Available also for PHP.
Available also for Python.
There is a standard approach to recursion and more data-types than what JSON allows, and it's part of the Structured Clone polyfill.
Beside acting as a polyfill, its @ungap/structured-clone/json
export provides both stringify
and parse
, and it's been tested for being faster than flatted, but its produced output is also smaller than flatted in general.
The @ungap/structured-clone module is, in short, a drop in replacement for flatted, but it's not compatible with flatted specialized syntax.
However, if recursion, as well as more data-types, are what you are after, or interesting for your projects/use cases, consider switching to this new module whenever you can 👍
1npm i flatted
Usable via CDN or as regular module.
1// ESM 2import {parse, stringify, toJSON, fromJSON} from 'flatted'; 3 4// CJS 5const {parse, stringify, toJSON, fromJSON} = require('flatted'); 6 7const a = [{}]; 8a[0].a = a; 9a.push(a); 10 11stringify(a); // [["1","0"],{"a":"0"}]
If you'd like to implicitly survive JSON serialization, these two helpers helps:
1import {toJSON, fromJSON} from 'flatted'; 2 3class RecursiveMap extends Map { 4 static fromJSON(any) { 5 return new this(fromJSON(any)); 6 } 7 toJSON() { 8 return toJSON([...this.entries()]); 9 } 10} 11 12const recursive = new RecursiveMap; 13const same = {}; 14same.same = same; 15recursive.set('same', same); 16 17const asString = JSON.stringify(recursive); 18const asMap = RecursiveMap.fromJSON(JSON.parse(asString)); 19asMap.get('same') === asMap.get('same').same; 20// true
As 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))
.
The 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.
Also 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.
.parse(string, reviver)
and revive your own objects.space
parameter to .stringify(object, replacer, space)
for feature parity with JSON signature.All ECMAScript engines compatible with Map
, Set
, Object.keys
, and Array.prototype.reduce
will work, even if polyfilled.
While stringifying, all Objects, including Arrays, and strings, are flattened out and replaced as unique index. *
Once parsed, all indexes will be replaced through the flattened collection.
*
represented as string to avoid conflicts with numbers
1// logic example 2var a = [{one: 1}, {two: '2'}]; 3a[0].a = a; 4// a is the main object, will be at index '0' 5// {one: 1} is the second object, index '1' 6// {two: '2'} the third, in '2', and it has a string 7// which will be found at index '3' 8 9Flatted.stringify(a); 10// [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"] 11// a[one,two] {one: 1, a} {two: '2'} '2'
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
4 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 0/26 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More