like-json v1.0.32
like-json
Stringify at perfect performance. +1200%
Benchmark it yourself: https://jsperf.com/likejson
Install
Node.js:
npm i like-jsonBrowser:
<script src="https://unpkg.com/like-json/index.min.js"></script>Features
Methods
like.json(obj: Object|Array|Any, options: Object): Function
like.stringify(obj: Object|Array|Any, uniqueId: Number, options: Object): StringExamples
json
const like = require('like-json');
let stringify = like.json({ msg: '' });
let string1 = JSON.stringify({ msg: 'account created' });
let string2 = stringify({ msg: 'account created' });
console.log(string1 === string2); // truestringify
const like = require('like-json');
let string1 = JSON.stringify({ msg: 'account created' });
let string2 = like.stringify({ msg: 'account created' }, 1);
console.log(string1 === string2); // trueHow it works?
There is no processing, so same than a simple concatenation:
console.log(stringify.toString());
// ->
function anonymous (o) {
return '{"msg":"' + o.msg + '"}';
}Because that there is a conflict with double quotes:
{ msg: 'account "user" created' } // object
{"msg":"account \"user\" created"} // JSON.stringify
{"msg":"account "user" created"} // like.stringifyYou can use single quotes, in that way avoid escape which reduces performance.\ If really want to use double quotes then can use options:
let options = { encode: true };
let string1 = JSON.stringify({ msg: 'account "user" created' });
let string2 = like.stringify({ msg: 'account "user" created' }, 2, options);
console.log(string1 === string2); // trueTests
npm testInside of stringify.test.js can see more info.
License
Code released under the MIT License.
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago