rfc_6901 0.2.0 copy "rfc_6901: ^0.2.0" to clipboard
rfc_6901: ^0.2.0 copied to clipboard

JSON Pointer (RFC 6901). Reads/writes referred values in JSON documents.

example/example.dart

import 'dart:convert';

import 'package:rfc_6901/rfc_6901.dart';

void main() {
  const json = '{"foo": [{"bar": 42}]}';
  final document = jsonDecode(json);
  print('Original document: $document');

  for (var expression in [
    '/foo', // reads the array
    '/foo/0', // reads the first element of the array
    '/foo/0/bar', // reads 42
  ]) {
    final pointer = JsonPointer(expression);
    print('Pointer "$pointer" reads ${pointer.read(document)}');
  }

  for (var expression in [
    '/foo/0/bar', // {foo: [{bar: banana}]}
    '/foo/-', // {foo: [{bar: 42}, banana]}
    '/a/b/-/c/d', // {foo: [{bar: 42}], a: {b: [{c: {d: banana}}]}}
  ]) {
    final pointer = JsonPointer(expression);
    final d = pointer.write(document, 'banana');
    print('Add a banana at "$pointer": $d');
  }
}
19
likes
160
pub points
78%
popularity

Publisher

verified publisherkarapetov.com

JSON Pointer (RFC 6901). Reads/writes referred values in JSON documents.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on rfc_6901