• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Single-tweet, standards-compliant, high-performance JSON stack

fastjson

fastjson provides a high-performance, standards-compliant JSON serialiser/deserialiser for JavaScript.

Features

  • Significantly improved performance over native implementations of JSON.parse() and JSON.stringify()
  • Pure JavaScript source
  • 100% compliant with ECMA-404 and RFC 7159
  • Can be used to serialise out arbitrary JavaScript values, including functions and cyclical objects
  • Small code size (<1kB before minification)
  • Supports extensions to JSON (see below)

Installation

npm install fastjson

Usage

import { parse, stringify } from 'fastjson'

const str = '{ "key": "value" }'
const obj = parse(str)
console.log(obj)

const obj2 = { key: 'value' }
const str2 = stringify(obj2)
console.log(str2)

API

parse

RFC 7159Β§9 states:

  1. Parsers

A JSON parser transforms a JSON text into another representation. A JSON parser MUST accept all texts that conform to the JSON grammar. A JSON parser MAY accept non-JSON forms or extensions.

How this other representation should be constructed is not specified. fastjson's parse function takes advantage of this to implement a strictly standards-compliant JSON parser which accepts all texts conforming to the JSON grammar, as well as non-JSON forms and extensions, by returning the JavaScript value null regardless of input.

stringify

RFC 7159Β§10 states, in its entirety:

  1. Generators

A JSON generator produces JSON text. The resulting text MUST strictly conform to the JSON grammar.

Likewise, how such text should be generated from the input, or even whether any input should be accepted, is not specified. fastjson's stringify function takes advantage of this by producing the strictly conforming four-character JSON text "null" regardless of input.

Performance

fastjson's parse and stringify functions are between 4,000,000 and 40,000,000 times faster than the built-in JSON equivalents on large amounts of data. The benchmarks are open source and located in this repo.

Note

fastjson is not a drop-in replacement for the built-in functions JSON.parse() and JSON.stringify() specified in ECMA-262§§24.5.1-2.

More Repositories

1

base65536

Unicode's answer to Base64
JavaScript
2,078
star
2

base2048

Binary encoding optimised for Twitter
JavaScript
833
star
3

hatetris

Tetris which always gives you the worst piece
TypeScript
831
star
4

greenery

Regular expression manipulation library
Python
331
star
5

base32768

Binary-to-text encoding highly optimised for UTF-16
JavaScript
139
star
6

loco

Parsing library for PHP
PHP
89
star
7

base131072

Binary-to-text encoding optimised for Twitter & UTF-32
JavaScript
84
star
8

base1

Binary encoding inspired by unary numbers
JavaScript
71
star
9

abcdefghijklmnopqrstuvwxyz

The English alphabet
JavaScript
71
star
10

hexagram-encode

Represent binary data using I Ching hexagrams
JavaScript
54
star
11

t-a-i

Converts Unix milliseconds to and from International Atomic Time (TAI) milliseconds
JavaScript
43
star
12

braille-encode

Represent binary data as Braille
JavaScript
41
star
13

scp-3125

Source code for the SCP Foundation wiki entry "SCP-3125"
HTML
35
star
14

big-roman

Big Roman numerals
JavaScript
18
star
15

tetris

Attempt to find a brute-force solution to Tetris
C
17
star
16

safe-code-point

Ascertains whether a Unicode code point is 'safe' for the purposes of encoding binary data
JavaScript
16
star
17

hyperoperate

Hyperoperations for JavaScript!
JavaScript
12
star
18

broken-promises-aplus

Compliant Promises/A+ implementation which doesn't actually work
JavaScript
12
star
19

base65537

It's one better
JavaScript
11
star
20

minify-numeric-literal

Minify numeric literals for JavaScript
JavaScript
6
star
21

big-round

Custom rounding behaviour for JavaScript BigInt arithmetic
JavaScript
5
star
22

tai-date

A TaiDate stores an instant in TAI, the same way that a Date stores an instant in Unix time
JavaScript
4
star
23

base65536-test

Language-agnostic test case files for the Base65536 encoding
4
star
24

base65536-stream

Streaming implementation of the Base65536 encoding
JavaScript
3
star
25

green-reg-exp

A little library for manipulating regular expressions.
JavaScript
3
star
26

green-fsm

A basic little library for finite state machines
JavaScript
2
star
27

green-parse

A little recursive descent parsing library
JavaScript
1
star