Coder Social home page Coder Social logo

fast-json-stringify's Introduction

fast-json-stringify  Build Status

fast-json-stringify is x1-5 times faster than JSON.stringify(). It is particularly suited if you are sending small JSON payloads, the advantages reduces on large payloads.

Benchmarks:

JSON.stringify array x 3,500 ops/sec ±0.91% (85 runs sampled)
fast-json-stringify array x 4,456 ops/sec ±1.68% (87 runs sampled)
JSON.stringify long string x 13,395 ops/sec ±0.88% (91 runs sampled)
fast-json-stringify long string x 95,488 ops/sec ±1.04% (90 runs sampled)
JSON.stringify short string x 5,059,316 ops/sec ±0.86% (92 runs sampled)
fast-json-stringify short string x 12,219,967 ops/sec ±1.16% (91 runs sampled)
JSON.stringify obj x 1,763,980 ops/sec ±1.30% (88 runs sampled)
fast-json-stringify obj x 5,085,148 ops/sec ±1.56% (89 runs sampled)

Example

const fastJson = require('fast-json-stringify')
const stringify = fastJson({
  title: 'Example Schema',
  type: 'object',
  properties: {
    firstName: {
      type: 'string'
    },
    lastName: {
      type: 'string'
    },
    age: {
      description: 'Age in years',
      type: 'integer'
    }
  }
})

console.log(stringify({
  firstName: 'Matteo',
  lastName: 'Collina',
  age: 32
}))

API

fastJsonStringify(schema)

Build a stringify() function based on jsonschema.

Supported types:

  • 'integer'
  • 'number'
  • 'array'
  • 'object'
  • 'boolean'
  • 'null'

And nested ones, too. Date instances are serialized with toISOString().

Acknowledgements

This project was kindly sponsored by nearForm.

License

MIT

fast-json-stringify's People

Contributors

mcollina avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.