1.2.14 • Published 9 months ago

doge-json v1.2.14

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
github
Last release
9 months ago

doge-json

Less verbose and more reliable JSON reading and writing.

import * as J from 'doge-json';

J.encode(obj) => string
J.decode(string) => obj
J.read(file) => obj
J.write(file, obj)

why less verbose?

import * as J from 'doge-json';

const a = { foo: 'bar' };

const b = J.encode(A);
// b is now a formatted JSON string

const c = J.decode(b);
// c is a new object, shaped { foo: 'bar' }
// native JSON needn't be imported

const a = { foo: 'bar' };

const b = JSON.stringify(A, null, 4);
// b is now a formatted JSON string

const c = JSON.parse(b);
// c is a new object, shaped { foo: 'bar' }

why more reliable?

const J = require('doge-json');

const a = typeof window === 'object' ? window : global;
// the global object

const b = J.encode(a);
// b is now a formatted JSON string

const c = J.decode(b);
// c is a new object, though much was lost due to the conversion
// native JSON needn't be imported

const a = typeof window === 'object' ? window : global;
// the global object

const b = JSON.stringify(a);
// throws a TypeError: Converting circular structure to JSON

const c = JSON.parse(b);
// this line is never reached, there is no JSON to parse

read/write files

import * as J from 'doge-json';

const pkg = J.read('package.json');
pkg.description = 'My awesome package!';
J.write('package.json', pkg);
1.2.14

9 months ago

1.2.13

9 months ago

1.2.12

2 years ago

1.2.11

2 years ago

1.2.10

2 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.0-1

4 years ago

1.2.0-3

4 years ago

1.2.0-2

4 years ago

1.2.1

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.0-3

4 years ago

1.1.0-2

4 years ago

1.1.0-1

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago