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
circular-json-for-egg
JSON does not handle circular references. This version does
macaca-circular-json
JSON does not handle circular references. This version does
flat-cache
A simple key/value storage using files to persist the data
flatpack-json
A library to normalize JSON objects to reduce the size.
npm install flatted
99.7
Supply Chain
100
Quality
85.5
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,048 Stars
135 Commits
47 Forks
10 Watching
4 Branches
10 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
JavaScript (66.27%)
PHP (19.38%)
Python (13.42%)
HTML (0.93%)
Cumulative downloads
Total Downloads
Last day
-8.1%
8,108,422
Compared to previous day
Last week
2.9%
47,994,991
Compared to previous week
Last month
15.7%
191,279,650
Compared to previous month
Last year
21.7%
1,874,500,295
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 binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
3 commit(s) and 2 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/25 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 2024-11-25
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