Comparing version 1.0.1 to 2.15.1
{ | ||
"name": "jsonic", | ||
"version": "1.0.1", | ||
"description": "A JSON parser that isn't strict.", | ||
"main": "jsonic.js", | ||
"scripts": { | ||
"test": "jasmine-node ./test ; phantomjs test/run-jasmine.js test/jasmine.html", | ||
"build": "./build.sh", | ||
"clean": "rm -rf node_modules yarn.lock package-lock.json", | ||
"reset": "npm run clean && npm i && npm run build && npm test", | ||
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"`; echo TAG: v$REPO_VERSION; git commit -a -m v$REPO_VERSION; git push; git tag v$REPO_VERSION; git push --tags;", | ||
"repo-publish": "npm run reset && npm run repo-tag && npm publish --registry http://registry.npmjs.org" | ||
}, | ||
"version": "2.15.1", | ||
"main": "dist/jsonic.js", | ||
"type": "commonjs", | ||
"browser": "dist/jsonic.min.js", | ||
"types": "dist/jsonic.d.ts", | ||
"description": "A dynamic JSON parser that isn't strict and can be customized.", | ||
"homepage": "https://github.com/rjrodger/jsonic", | ||
"keywords": [ | ||
"pattern", | ||
"matcher", | ||
"object", | ||
"property", | ||
"json" | ||
], | ||
"author": "Richard Rodger (http://richardrodger.com)", | ||
"repository": { | ||
@@ -18,24 +22,45 @@ "type": "git", | ||
}, | ||
"keywords": [ | ||
"json", | ||
"parser" | ||
], | ||
"homepage": "https://github.com/rjrodger/jsonic", | ||
"author": "Richard Rodger (http://richardrodger.com)", | ||
"scripts": { | ||
"test": "jest --coverage", | ||
"test-open": "jest --coverage --detectOpenHandles", | ||
"test-pure": "jest --coverage --config jest.config.pure.js", | ||
"test-some": "jest -t", | ||
"test-watch": "jest --coverage --watchAll", | ||
"test-view": "open coverage/lcov-report/index.html", | ||
"watch": "tsc -w -d", | ||
"build": "tsc -d", | ||
"diagrams": "docs-src/.vuepress/diagrams/generate.sh", | ||
"coveralls": "lab -s -P test -r lcov | coveralls", | ||
"prettier": "prettier --write --no-semi --single-quote src/*.ts test/*.js", | ||
"docs-dev": "vuepress dev docs-src", | ||
"docs-build": "vuepress build docs-src", | ||
"clean": "rm -rf node_modules dist yarn.lock package-lock.json", | ||
"reset": "npm run clean && npm i && npm run build && npm test", | ||
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;", | ||
"repo-publish": "npm run clean && npm i && npm run repo-publish-quick", | ||
"repo-publish-quick": "npm run prettier && npm run build && npm run test && npm run repo-tag && npm publish --registry https://registry.npmjs.org --access=public" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"README.md", | ||
"LICENSE", | ||
"jsonic.js", | ||
"jsonic-min.js", | ||
"jsonic-min.map", | ||
"jsonic-parser.js", | ||
"jsonic-parser.pegjs" | ||
"dist", | ||
"bin", | ||
"LICENSE" | ||
], | ||
"bin": { | ||
"jsonic": "bin/jsonic" | ||
}, | ||
"exports": { | ||
".": "./dist/jsonic.js", | ||
"./debug": "./dist/debug.js" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": "^3.0.0", | ||
"pegjs": "^0.10.0", | ||
"phantomjs": "^2.1.7", | ||
"uglify-js": "^3.10.4" | ||
"@jsonic/directive": "^0.12.0", | ||
"@types/jest": "^29.5.14", | ||
"es-jest": "^2.1.0", | ||
"esbuild": "^0.24.0", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.3.3", | ||
"typescript": "^5.6.3", | ||
"@jsonic/csv": "^0.5.0" | ||
} | ||
} |
285
README.md
# jsonic | ||
[![npm version][npm-badge]][npm-url] | ||
[![Build Status][travis-badge]][travis-url] | ||
[![Dependency Status][david-badge]][david-url] | ||
NOTE: PREVIEW VERSION OF NEXT RELEASE | ||
*A JSON parser for JavaScript that isn't strict. | ||
Also, it's very __very__ extensible.* | ||
### A JSON parser for Node.js that isn't strict. | ||
`a:1,foo:bar` → `{"a": 1, "foo": "bar"}` | ||
[Site](https://jsonic.com/) | | ||
[Docs](https://jsonic.com/docs) | | ||
[FP Guide](https://github.com/jsonic/jsonic/wiki/FP-Guide) | | ||
[Contributing](https://github.com/jsonic/jsonic/blob/master/.github/CONTRIBUTING.md) | | ||
[Wiki](https://github.com/jsonic/jsonic/wiki "Changelog, Roadmap, etc.") | | ||
[Code of Conduct](https://code-of-conduct.openjsf.org) | | ||
[Twitter](https://twitter.com/bestiejs) | | ||
[Chat](https://gitter.im/jsonic/jsonic) | ||
A JSON parser that can parse "bad" JSON. Mostly, this is about | ||
avoiding the need to quote everything! | ||
Strict JSON requires you to do this: | ||
[](https://badge.fury.io/js/jsonic) | ||
[](https://david-dm.org/rjrodger/jsonic) | ||
```JavaScript | ||
{ "foo":"bar", "red":1 } | ||
``` | ||
# Quick start | ||
The JavaScript language itself is a little easier: | ||
Install: | ||
```JavaScript | ||
{ foo:"bar", red:1, } | ||
``` | ||
> npm install jsonic | ||
``` | ||
But if you really want to be lazy, jsonic lets you say: | ||
Node.js: | ||
``` | ||
const Jsonic = require('jsonic') | ||
console.log(Jsonic('a:b')) // prints {a:'b'} | ||
``` | ||
```JavaScript | ||
foo:bar, red:1, | ||
TypeScript: | ||
``` | ||
import { Jsonic } from 'jsonic' | ||
console.log(Jsonic('a:b')) // prints {a:'b'} | ||
``` | ||
See below for the relaxed JSON rules. | ||
Browser: | ||
``` | ||
<script src="jsonic.min.js"></script> | ||
<script> | ||
console.log(Jsonic('a:b')) // prints {a:'b'} | ||
</script> | ||
``` | ||
(Although in the real world you'll probably be packaging _jsonic_ as a dependency with _webpack_ or similar.) | ||
This module is used by the [Seneca](http://senecajs.org) framework to | ||
provide an abbreviated command syntax. | ||
### Support | ||
# What can jsonic do? | ||
If you're using this module, feel free to contact me on twitter if you have any questions! :) [@rjrodger](http://twitter.com/rjrodger) | ||
All of the examples below parse beautifully to `{"a": 1, "b": "B"}`. | ||
### Quick example | ||
```JavaScript | ||
var jsonic = require('jsonic') | ||
*short and sweet* | ||
``` | ||
a:1,b:B | ||
``` | ||
// parse a string into a JavaScript object | ||
var obj = jsonic('foo:1, bar:zed') | ||
*no commas, no problem* | ||
``` | ||
a:1 | ||
b:B | ||
``` | ||
// prints { foo: 1, bar: 'zed' } | ||
console.dir( obj ) | ||
*comments are cool* | ||
``` | ||
a:1 | ||
// a:2 | ||
# a:3 | ||
/* b wants | ||
* to B | ||
*/ | ||
b:B | ||
``` | ||
## Install | ||
*strings and things* | ||
```sh | ||
npm install jsonic | ||
``` | ||
{ "a": 100e-2, '\u0062':`\x42`, } | ||
``` | ||
The syntax of _jsonic_ is just easy-going JSON: | ||
* simple no-quotes-needed property names: `{a:1}` → `{"a": 1}` | ||
* implicit top level (optional): `a:1,b:2` → `{"a": 1, "b": 2}`, `a,b` → `["a", "b"]` | ||
* graceful trailing commas: `a:1,b:2,` → `{"a": 1, "b": 2}`, `a,b,` → `["a", "b"]` | ||
* all the number formats: `1e1 === 0xa === 0o12 === 0b1010` | ||
# Relaxed Rules | ||
JSONIC format is just standard JSON, with a few rule relaxations: | ||
But that is not all! Oh, no. That is not all... | ||
* You don't need to quote property names: <code>{ foo:"bar baz", red:255 }</code> | ||
* You don't need the top level braces: <code>foo:"bar baz", red:255</code> | ||
* You don't need to quote strings with spaces: <code>foo:bar baz, red:255</code> | ||
* You _do_ need to quote strings if they contain a comma or closing brace or square bracket: <code>icky:"_,}]_"</code> | ||
* You can use single quotes for strings: <code>Jules:'Cry "Havoc," and let slip the dogs of war!'</code> | ||
* You can have trailing commas: <code>foo:bar, red:255, </code> | ||
This: | ||
# Stringify | ||
``` | ||
# Merge, baby, merge! | ||
cat: { hat: true } | ||
cat: { fish: null } | ||
cat: who: ['sally', 'me'] | ||
# Who needs quotes anyway? | ||
holds up: [ | ||
cup and a cake, | ||
The _jsonic_ module provides a `stringify` method: | ||
`TWO books! | ||
the fish!`, | ||
``` js | ||
console.log( jsonic.stringify( {a:"bc",d:1} ) ) // prints {a:bc,d:1} | ||
''' | ||
ship! | ||
dish! | ||
ball! | ||
''' | ||
] | ||
} | ||
``` | ||
The `stringify` method converts a plain JavaScript object into a | ||
string that can be parsed by _jsonic_. It has two parameters: | ||
parses into this: | ||
* `value`: plain object | ||
* `options`: optional options object | ||
``` | ||
{ | ||
"cat": { | ||
"hat": true, | ||
"fish": null, | ||
"who": ["sally","me"] | ||
}, | ||
"holds up": [ | ||
"cup and a cake", | ||
"TWO books!\n the fish!", | ||
"ship!\ndish!\nball!" | ||
] | ||
} | ||
``` | ||
For example, you can limit the depth of the object tree printed: | ||
``` js | ||
console.log( jsonic.stringify( {a:{b:{c:1}}}, {depth:2} ) ) // prints {a:{b:{}}} | ||
Meaning you also get: | ||
* quotes can be single or double ': `'a',"b"` → `['a', 'b']` | ||
* quotes are optional, even with spaces: `{a: cup cake }` → `{"a": "cup cake"}` | ||
* object merging: `a:{b:1},a:{c:2}` → `{"a": {"b": 1, "c": 2}}` | ||
* object construction: `a:b:1,a:c:2` → `{"a": {"b": 1, "c": 2}}` | ||
* multi-line strings: | ||
``` | ||
`a | ||
b` | ||
``` | ||
→ `"a\nb"` | ||
* indent-adjusted strings: | ||
``` | ||
''' | ||
a | ||
b | ||
''' | ||
``` | ||
→ `"a\nb"` | ||
__NOTE: `jsonic.stringify` is intended for debug printing, not data exchange, so the defaults are conservative in the amount of data printed__ | ||
The options are: | ||
And we haven't even begun to talk about all the fun stuff you can do | ||
with options and plugins, including support for multiple files, | ||
CSV (or TSV), and dynamic content. | ||
* _depth_: default: __3__; maximum depth of sub-objects printed; _NOTE: there is no infinite-cycle protection, just this finite depth_ | ||
* _maxitems_: default: __11__; maximum number of array elements or object key/value pairs printed | ||
* _maxchars_: default: __111__; maximum number of characters printed | ||
* _omit_: default:__[]__; omit listed keys from objects | ||
* _exclude_: default:__['$']__; omit keys from objects if they contain any of the listed values | ||
<details open="open"> | ||
<summary>Table of Contents</summary> | ||
<ol> | ||
<li> | ||
<a href="#about-the-project">About The Project</a> | ||
<ul> | ||
<li><a href="#built-with">Built With</a></li> | ||
</ul> | ||
</li> | ||
<li> | ||
<a href="#getting-started">Getting Started</a> | ||
<ul> | ||
<li><a href="#prerequisites">Prerequisites</a></li> | ||
<li><a href="#installation">Installation</a></li> | ||
</ul> | ||
</li> | ||
<li><a href="#usage">Usage</a></li> | ||
<li><a href="#roadmap">Roadmap</a></li> | ||
<li><a href="#contributing">Contributing</a></li> | ||
<li><a href="#license">License</a></li> | ||
<li><a href="#contact">Contact</a></li> | ||
<li><a href="#acknowledgements">Acknowledgements</a></li> | ||
</ol> | ||
</details> | ||
## How it Works | ||
The parser uses [PEG.js](http://pegjs.majda.cz/) and is an extension of the example JSON parser included in that project. | ||
[npm-badge]: https://badge.fury.io/js/jsonic.svg | ||
[npm-url]: https://badge.fury.io/js/jsonic | ||
[travis-badge]: https://api.travis-ci.org/rjrodger/jsonic.svg | ||
[travis-url]: https://travis-ci.org/rjrodger/jsonic | ||
[david-badge]: https://david-dm.org/rjrodger/jsonic.svg | ||
[david-url]: https://david-dm.org/rjrodger/jsonic | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
a | ||
# Usage | ||
# Breaking Changes | ||
* unterminated strings? | ||
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
327897
34
4859
270
8
3
1