0.0.10 • Published 10 years ago

json-rel v0.0.10

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

json-rel

:link: Transparent references in JSON


json-rel converges the following standards and libraries in order to help normalize JSON reference/relationship descriptors:

The goal is to increase developer transparency and to provide a unified, semantic interface for working with related JSON data.

Aside from being all around simple, json-rel spares library developers from having to:

  1. decide between which reference specifications(s) to support in your projects
  2. write an interface for when more than one standard needs support
  3. bottleneck integrators of your library into a certain specificaton
  4. write a mechanism that provides a consistent return format (e.g. array vs. element)

Installation

npm install json-rel

Usage

This example shows how to use the main feature of json-rel, which is being able to provide any relationship or reference string to $, an "operator" which will automatically identify the correct specification to use based on the relation itself:

import $ from 'json-rel'

const data = {
  foo: {
    bar: true
  }
}

let query   = $('foo.bar').use(data).get()   // true
let path    = $('$.foo.bar').use(data).get() // true
let pointer = $('/foo/bar').use(data).get()  // true

If you want to be slightly more concise:

let query   = $('foo[bar]', data).get()  // true
let path    = $('$.foo.bar', data).get() // true
let pointer = $('/foo/bar', data).get()  // true

You may also, of course, access and use each specification individually:

import {query, path, pointer} from 'json-rel'

query('foo[bar]', data).get()   // true
path('$.foo.bar', data).get()   // true
pointer('/foo/bar', data).get() // true

You can also infer the specification directly from the relation itself via which:

import which from 'json-rel'

which('foo[bar]')  // -> json-query
which('$.foo.bar') // -> json-path
which('/foo/bar')  // -> json-pointer
0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago