Viewing version 0.0.1. Open the latest package page.

json_pointer

0.0.1

A simple library for creating and using json-pointer (See [rfc6901:https://tools.ietf.org/html/rfc6901]).

Download archive

Readme

JSON Pointer

A simple library for creating and using json-pointer (See rfc6901).

Examples

  // Json Pointer Manipulation
  compose(['one', 'two']); // '/one/two'
  split('/one/two'); // ['one', 'two']
  parent('/one/two'); // '/one'
  append('/one', 'two'); // '/one/two'
  contains('/0/foo', [{'foo': 'bar'}]); // true
  isValid('/one/two'); // true

  // Json Pointer Part manipulation
  escape('one/two'); // 'one~1two'
  unescape('one~1two'); // 'one/two'

  // Get and Set values in a json object
  var obj = [
    {'foo': 'bar'}
  ]

  get$('/0/foo', obj); // 'bar'
  set$('/0/foo', obj, 'baz'); // [{'foo': 'baz'}]

Escaping Examples

  // Compose escapes parts
  compose(['one/two', 'three']); // '/one~1two/three'

  // Append escapes the added part
  append('/one', 'two/three'); // '/one/two~1three'

  // Split unescapes parts
  split('/one~1two/three'); // ['one/two', 'three']

Get, Set, and Contains

The library is only able to index into Map and List. get$ and set$ will throw BadRouteError when attempting to index into other types and contains will return false.

class Point {
  Point(this.x, this.y);
  int x;
  int y;
}

contains('/x', Point(0, 0)) // false
contains('', Point(0, 0)) // true, this is ok as Point is never indexed 

BadRouteError

get$ and set$ throw BadRouteError if the pointer doesn't refer to valid route through json. an object in the 'root' parameter (e.g. contains(path, root) == false). Set can only be used to change an existing value. It will not attempt to insert into a List or Map.

get('/3', [0, 1, 2]) // BadRouteError
set('/3', [0, 1, 2], 'three') // BadRouteError
set('/foo', {}, 'bar') // BadRouteError

PointerFormatError and PartFormatError

All functions that accept a json pointer as an argument will throw PointerFormatError if not isValid(pointer). Similarly, unescape checks for a valid part and throws PartFormatError if the format is invalid.

split('0/foo') // PointerFormatError
split('~2/foo') // PointerFormatError: 
split(null) // PointerFormatError: null pointer
unescape('/') // PointerFormatError: part cannot contain the '/' character
Changelog

0.0.0

Initial version

0.0.1

Documentation and project fomatting changes

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'json_pointer:0.0.1'
pubspec.yaml
name: json_pointer
description: A simple library for creating and using json-pointer (See [rfc6901:https://tools.ietf.org/html/rfc6901]).
author: 'Pete <petedmc0@gmail.com>'
version: '0.0.1'
homepage: 'https://none.com'

environment:
  sdk: '>=2.4.0 <3.0.0'

#dependencies:
#  path: ^1.6.0

dev_dependencies:
  pedantic: ^1.7.0
  test: ^1.6.0

Version history

VersionPublishedArchiveSHA-256
0.0.0Cached · Upstream SHA-256 matchedDownloadfd43fe8f…ecd88f
0.0.1Cached · Upstream SHA-256 matchedDownload30e024ac…d1d8b5
0.1.0Cached · Upstream SHA-256 matchedDownloadfcac1865…eef4eb

Dependencies

No direct dependencies declared.