Nuclear Powered Marshmallows
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

object-tojson

1.0.1 • Public • Published

object-tojson

Turn a Javascript primitive into its "flat" representation. Aims to be equivalent to JSON.parse(JSON.stringify(obj)). Note that it will recursively visit all properties and attempt to call toJSON, before trying to parse the value. undefined is not a valid JSON value, so it will attempt to remove properties that resolve to this value, unless it is an array element, in which case it resolves to null

Usage

 
const serialise = require('object-tojson')
 
serialise({
  key: 'value',
  arr: [undefined, null, true],
  keyFn: {toJSON: function () { return 'valueFn' }}
}) // => {key: 'value', [null, null, true], keyFn: 'valueFn'}

License

ISC

install

npm i object-tojson

Downloadsweekly downloads

40

version

1.0.1

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability