GithubHelp home page GithubHelp logo

nvdnkpr / jsonary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jsonary-js/jsonary

0.0 3.0 0.0 9.66 MB

Quickly assemble clients for JSON-based APIs (powered by JSON Schema)

Home Page: http://jsonary.com/

License: MIT License

jsonary's Introduction

Jsonary

Jsonary is a wrapper for JSON data, that deals with JSON Schema. Its goal is to help quickly assemble clients for JSON APIs.

It is written in JavaScript. Currently, it is being developed and tested for in-browser use. However, Node.js support is planned, with the goal of being able to write a single client that can be used either in-browser using AJAX, or as an HTML-only interface for non-JS browsers.

The primary goal of this library is not validation of data, but rather to simplify the fetching, handling and rendering of data. Its focus is correctly assigning JSON Schema to data, which can then be used to select and inform user-interfaces.

Using schemas

The core of Jsonary deals with JSON Schema (including hyper-schema). For example, here we create a Jsonary data wrapper, and apply a schema to it:

var data = Jsonary.create({
    "title": "Example data"
});
var schema = Jsonary.createSchema({
    "title": "Example schema",
    "type": "object",
    "properties": {
        "title": {
            "type": "string",
            "minLength": 1
        }
    },
    "required": ["title"]
});
data.addSchema(schema);

The data can be inspected or manipulated, like so:

alert(data.property('title').value());
data.property('message').setValue("Hello, world!");

The schema constraints can be inspected, like so:

alert(data.schemas().length); // 1
alert(data.schemas().requiredProperties()); // ["title"]

var title = data.property("title");
alert(title.schemas().minLength()); // 1

More complicated behaviour (such as selecting schemas from "anyOF", "oneOf", "dependencies", etc) is also handled automatically. Just change the data, and the schemas change with it.

Using hyper-schemas

Hyper-schemas can define links on the data, with the URLs parameterised from the data itself:

var data = Jsonary.create({
    "id": 125,
    "authorId": 25,
    "title": "Example data"
});
var schema = Jsonary.createSchema({
    "title": "Example hyper-schema",
    "links": [
        {
            "rel": "self":,
            "href": "http://example.com/items/{id}"
        }
        {
            "rel": "author",
            "href": "http://example.com/users/{authorId}"
        }
    ]
});
data.addSchema(schema);

Jsonary handles these, and the links can be inspected:

alert(data.links().length); // 2

var authorLink = data.links('author')[0];
alert(authorLink.href); // http://example.com/users/25

Many more properties of links can be inspected

Rendering clients

Jsonary comes bundled with a rendering system that bases its interface on the schemas that a data object has applied to it.

data.renderTo(document.getElementById('render-container'));

Main site

More information can be found at: jsonary.com, although this is now slightly out-of-date.

There is a quick feature tour, walkthroughs for creating a generic browser or creating a Facebook client (incomplete).

There is also a demo of how the default editable interface deals with various JSON Schema validation keywords here.

License

Jsonary is released under an MIT License.

The files in the directory renderers/separate-license may have separate licenses. To keep the licensing for Jsonary clean, they are not included in any of the bundles.

jsonary's People

Contributors

fidian avatar geraintluff avatar ognian avatar platy avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.