This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including really-relaxed-json
with all npm
packages installed. Try it out:
//import {toJs, toJson, toRJson, prettyPrint, Options, createParser} from 'really-relaxed-json'
// Use import if you can.
const rrj = require('really-relaxed-json');
const toJson = rrj.toJson;
const toRJson = rrj.toRJson;
const toJs = rrj.toJs;
const prettyPrint = rrj.prettyPrint;
const Options = rrj.Options;
const createParser = rrj.createParser;
const results = [];
// Converting RJSON to JSON
results['compact-json'] = toJson('[ one two three {foo:bar} ]');
results['pretty-json'] = toJson('[ one two three {foo:bar} ]', false);
// Converting JSON to RJSON
results['compact-rjson'] = toRJson('[ "one", "two", "three", {"foo": "bar"} ]');
// Converting JSON to Javascript
results['compact-js'] = toJs('[ "one", "two", "three", {"foo": "bar"} ]');
// Parsing
const parser = createParser();
const jsonValue = parser.stringToValue('[ one two three {foo:bar} ]');
// Now use or inspect the value object...
results['jsonValueString'] = jsonValue.toString(); // JsonValue.toString() will print compact JSON
results['stringToJson'] = parser.stringToJson('[ one two three {foo:bar} ]');
// Formatting / Converting
results['prettyFromValue'] = prettyPrint(Options.JsonPretty, jsonValue);
results['prettyFromString'] = prettyPrint(Options.JsonPretty, '[ one two three {foo:bar} ]');
results;
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.