# json_pointer 0.0.1

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




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'json_pointer:0.0.1'
```
Published: 2019-09-28T02:59:16.848452Z
Expected archive SHA-256: 30e024acb68d4f1478dceab6efd9bbd9b09670a31969e47fd62d7b62d4d1d8b5

Available in cache; verification: upstream_checksum
## Direct dependencies

## Package README (untrusted upstream documentation)
# JSON Pointer

A simple library for creating and using json-pointer (See [rfc6901](https://tools.ietf.org/html/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






 
