0.0.4 • Published 8 years ago

jsone-ui v0.0.4

Weekly downloads
8
License
MIT
Repository
github
Last release
8 years ago

jsone

JSON Editor with configurable editing, validation and documentation using json schema. Great for providing an easy guided way to edit and view JSON.

This project is under heavy development. Do not adopt yet. Try the demo

demo.png

Basic Usage (web component)

<jsone id="jsone" data-json="demoJSON.json" data-schema="demoSchema.json"></jsone>
<script src="jsone.js"></script>

Basic Usage (javascript)

var demo = new jsone({
    node: document.getElementById('jsone'), // target html element to place jsone
    json: 'demoJSON.json', // js object or url to jsone file
    schema: 'demoSchema.json' // js object or url to schema file
});

demo.on('change', function(path){
    console.log('change to path', path);

    demo.getChanges().forEach(function(change){
        console.log('path', change.path, 'changed to', change.value)
    })
})

Webpack/NPM

    require('jsone-ui');

Config Options

// when using the <jsone> tag to display jsone, all of these configurations will be attributes
// prefixed by data- (to satisfy w3c) and all non-string values will be JSON.parse'd
{
    "node": "", // the html element to populate with the jsone ui
    "json": "", // a javascript object or the URL to the JSON file to use
    "schema": "", // a javascript object or the URL to the JSON file to use as the schema/rules for the JSON file
    "hashnavigation": false, // (boolean) use window.locaton.hash to provide browser history back/foward
    "urlreplace": {}, // (object) a key/value object of replace from/replace to strings for URL's which is handy for local dev testing schema's,
    "jsonname": automatic, // (string) a string to name the json file/object being edited
}

Events

nameargumentsdescription
errorerror objectthere is an error of any kind
initnulljsone is initialized and is going to try to get the schema/json files
schemareadynullthe schema and all referenced schema's are loaded and ready
jsonreadynullthe JSON is loaded and the schema is associated with it
changepathstring, valuewhen a change is made this event emits the path as a string delimited by "/" to the changed node
autofixpathstring, value, change objectwhen a json file node type is different than the schema type it is automatically fixed and this event is fired for every node that is fixed

Methods

nameargumentsdescription
onevent, callbackexecutes call back on the specified event
getChangesnullreturns an array of changes with the path (array) joinpath (path string) and value of each change
jsonjson url or javascript objectchange the active json file
schemaschema url or javascript objectchange the active schema file

Schema Support

The schema's used with jsone try to conform to the jsone schema spec at http://json-schema.org/ and use the same structure of properties, items, definitions and references. It should be compatible with the structure starting now and feature gaps will be filled over time.

Local Dev/Local Demo

Needs to run on localhost for XMLHttpRequest to grab files from the local disk.

python -m SimpleHTTPServer 8080
http://localhost:8080/demo.html

jsone

Pronounced "jase own" and is a play off "json for everyone" or "jsone editor" as it fills both needs.

License

MIT