
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
json-stringify-extended
Advanced tools
JSON.stringify any data types
npm i json-stringify-extended
const stringify = require('json-stringify-extended')
const data = {
a: 'basic set, default options',
b: 1,
c: true,
d: function (a, b) { console.log(a + b) },
e: {a: 0, b: 0.1, c: -2},
f: ['a', 'b', 'c'],
g: new Date('2017-01-01'),
h: /a|b/,
i: null,
j: Infinity,
k: NaN,
l: undefined,
m: stringify.deferred('my.enum.VALUE'),
n: Buffer.from('7468697320697320612074c3a97374', 'hex')
}
console.log(stringify(data))
// output
{
a:"basic set, default options",
b:1,
c:true,
d:function (a, b) { console.log(a + b) },
e:{
a:0,
b:0.1,
c:-2
},
f:[
"a",
"b",
"c"
],
g:new Date("2017-01-01T00:00:00.000Z"),
h:/a|b/,
i:null,
j:Infinity,
k:NaN,
l:undefined,
m:my.enum.VALUE,
n:Buffer.from("dGhpcyBpcyBhIHTDqXN0")
}
StringNumberBooleanfunctionObjectArrayDateRegExpBuffernullInfinityNaNundefinedstringify.deferredStringify data into string
Type: any
Type: Object
Options to adjust result format.
You can also use prepared options:
stringify.options.json
format to regular JSON formatstringify.options.standadjs
format using standadjs rulesstringify.options.compact
format without folding, quotes and spacesexample
const data = {a: 'string', b: false, c: [0, 1, 2]}
console.log(stringify(data, stringify.options.compact))
// output
{a:'string',b:false,c:[0,1,2]}
Type: Boolean
Default: false
Works in safe mode, so will not throws exception for circularity.
Type: String
Default: \n
Endline string, should be only spacing chars as \n or \r\n. Set to empty string '' for one line output.
Type: String
Default: (two spaces)
Indentation string, should contains only spacing chars as \t or spaces .
Type: Boolean
Default: false
Compress data for function and Date discard null and undefined values, but don't remove spaces and useless quotes.
Type: function(key:String, value:String) return Boolean
Default: null
Use function to filter by key and/or value each element.
Return true to keep element or false to discard.
filter is applied before replace.
example
const data = {
user: 'alice',
password: 'it-s-a-secret',
id: 1,
meta: ['1', 1],
greet: function() { return 'hi' }
}
const options = {
filter: function (key, value) {
if (key === 'password') {
return false
}
if (value === 1) {
return false
}
if (typeof value === 'function') {
return false
}
return true
}
}
console.log(stringify(data, options))
// output
{
user:"alice",
meta:[
"1"
]
}
Type: function(key:String, value:String) return {key, value}
Default: null
Use function to replace key and/or value of each element.
Must return an object {key, value}.
filter is applied before replace.
example
const data = {
user: 'alice',
password: 'it-s-a-secret',
id: 1,
meta: ['1', 1]
}
const options = {
replace: function (key, value) {
if (key === 'password') {
return {key: 'secret', value: '***'}
}
if (value === 1) {
return {key, value: 'one'}
}
return {key, value}
}
}
console.log(stringify(data, options))
// output
{
user:"alice",
secret:"***",
id:"one",
meta:[
"1",
"one"
]
}
Type: String
Default: null
Character used for quote keys, default is null, means no quotes in keys. Should be " or ' or null
Type: String
Default: '
Character used for quote values, default is '. Should be " or '
Type: Boolean
Default: false
Add a space beetwen key: and value.
Type: Boolean
Default: false
Discard null and undefined values.
The MIT License (MIT)
Copyright (c) 2017-2018 braces lab
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
JSON.stringify with extended data types support
The npm package json-stringify-extended receives a total of 44 weekly downloads. As such, json-stringify-extended popularity was classified as not popular.
We found that json-stringify-extended demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.