2.16.0 • Published 5 months ago

jsonic v2.16.0

Weekly downloads
19,437
License
MIT
Repository
github
Last release
5 months ago

jsonic

NOTE: PREVIEW VERSION OF NEXT RELEASE

A JSON parser for JavaScript that isn't strict. Also, it's very very extensible.

a:1,foo:bar {"a": 1, "foo": "bar"}

Site | Docs | FP Guide | Contributing | Wiki | Code of Conduct | Twitter | Chat

npm version dependencies Status

Quick start

Install:

> npm install jsonic

Node.js:

const Jsonic = require('jsonic')
console.log(Jsonic('a:b'))  // prints {a:'b'}

TypeScript:

import { Jsonic } from 'jsonic'
console.log(Jsonic('a:b'))  // prints {a:'b'}

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.)

What can jsonic do?

All of the examples below parse beautifully to {"a": 1, "b": "B"}.

short and sweet

a:1,b:B

no commas, no problem

a:1
b:B

comments are cool

a:1
// a:2
# a:3

/* b wants 
 * to B
 */
b:B

strings and things

{ "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

But that is not all! Oh, no. That is not all...

This:

# Merge, baby, merge!
cat: { hat: true }
cat: { fish: null }
cat: who: ['sally', 'me']
  
# Who needs quotes anyway?
holds up: [
  cup and a cake,

  `TWO books!
   the fish!`,

  '''
  ship!
  dish!
  ball!
  '''
  ]
}

parses into this:

{
  "cat": {
    "hat": true,
    "fish": null,
    "who": ["sally","me"]
  },
  
  "holds up": [
    "cup and a cake",
    "TWO books!\n   the fish!",
    "ship!\ndish!\nball!"
  ]
}

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"

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.

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?
bittrex-api-nodenode-bittrex-api-perfdvdp@flexdrive/seneca-mesh@flexdrive/seneca-nats-streaming@infinitebrahmanuniverse/nolb-jsoni@everything-registry/sub-chunk-1987talk-to-resolvetalk-to-senecaswagger-seneca-routertethvidi-seneca-metricsvidstreaming-scrapervidstreaming-scrappervickymdexocom-dev@doneill/seneca-mesh@cocalc/frontend@cocalc/utiljson-fixjson-from-textjsonitjsonic-clilavenzalaposte-okapi-clistreammoe-scrappervevio-scraper@0xgg/echomd4xx@brad-jones/cc-tokenizer-server@devninjas/chairo@dfurnes/heyyves-clixrp-replzer0-buszenozod-gpt@givanse/node-bittrex-api@ekliptor/node-bittrex-api-fix@mdblog/mdblog@mdblog/plugin-dirtree@mdblog/plugin-orgchart@metric-im/componentry@metric-im/data-server@metric-im/metric-server@neo4j/neo4j-browser-canary@namics/nitro-component-handlebars@famished-int/seneca-amqp-transport-observe@ofa2/ofa2-seneca-amqp-transport@qxip/promql2logql@picosix/cli@picosix/core@nscale/seneca-balance-clientminicofa-seneca-amqp-transportparambulatorseneca-transport-ngseneca-transport-zhseneca-utilsseneca-servicebus-transportseneca-zyre-transportseneca-replseneca-ngseneca-pinsenecaseneca-adminseneca-amqp-transportseneca-amqp-transport-altseneca-amqp-transport-fixed-versionsseneca-balance-clientseneca-balance-client-ngseneca-chainseneca-cliseneca-legacyseneca-legacy-loggerseneca-decreeseneca-demo-loggerseneca-extendseneca-handlerseneca-msg-testseneca-entitiesseneca-meshseneca-mesh-ngseneca-compatsensonnode-bittrex-apinode-bittrex-api-ovaleneo4j-etl-uineo4j-browserneo4j-browser-image-enabledneo4j-browser-reactngx-do-api-gatewayngx-do-proxynode.bittrex.apinode.bittrex.api-modnode_emurest-router-modelqugetredo-jsonqryn
2.15.2

8 months ago

2.16.0

5 months ago

2.15.1

8 months ago

1.0.1

5 years ago

0.3.1

7 years ago

0.3.0

8 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

12 years ago

0.1.0

12 years ago