1.4.0 • Published 4 years ago

statham v1.4.0

Weekly downloads
83
License
ISC
Repository
github
Last release
4 years ago

Statham

What

statham is a layer on top of JSON that handles object references.

It takes inspiration from https://github.com/graniteds/jsonr

Usage

statham.stringify(value, replacer, spacer)

Grab it: var statham = require('statham');

Make something you can't JSON.stringify:

var myObj = {};

// Circular reference
myObj.thing = myObj;

Stringify it:

var myJsonString = statham.stringify(myObj);

The output looks like:

{"thing":"","":""}

Then to inflate it:

statham.parse(value, reviver)

var inflatedObj = statham.parse(myJsonString);

Which will look like:

{
    thing: inflatedObj
}

You can also optionally revive an object that has statham markers in it by calling:

var legitObject = statham.revive(stathamMarkeredObject);

This is useful when someone else got to the json before you, and did:

var stathamMarkeredObject = JSON.parse(stathamStringifiedJSON);

Which will work without issue, but still have all the statham markers in it.

How

statham uses extremely rarely used string characters above \uE000 to mark references.

When it scans an object, if it notices an object referenced in more than one spot, it will add a reference property () with a key character assigned to it.

On deflation, statham will grab all objects with the  property, and inflate any properties that have it's key with that object.

Why 'statham'?

stathum is all about references in JSON, Statham is a reference to Jason Statham, cuz he's the most famous Jason I could think of.

1.4.0

4 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago