serialize-js
v1.1.0
Published
User-readable object serialization for JavaScript.
Downloads
2,100
Maintainers
Readme
serialize-js
What's this?
Small serialization helper for those who wants to get JS representation of object but gets only this dirty JSON.
Why does it exist?
Sometimes it's useful to serialize object into the JS user-readable representation but the only option you have is JSON which adds all this damn quotes around any keys (incl. valid identifiers), indents entire contents of any objects/arrays etc.
This small serializer allows you to overcome that and get pretty representations, just as you would write it with own hands in code:
How can I customize the output?
You can optionally pass options object as second argument (serialize(obj, { /*...options...*/ })
).
Possible options are below:
initialIndent
Type: String
Default: ''
Initial indentation of output (generated indentation will be relative to this one).
indent
Type: Number|String
Default: 2
Indentation to be used for nested representations; it can be either number of spaces or explicit string (like '\t'
).
forceJSON
Type: Boolean
Default: false
If set to true
, generates JSON-compatible output (all the keys are wrapped with quotes, but indentation is still optimized).