Viewing version 0.2.1. Open the latest package page.
rfc_6901
0.2.1JSON Pointer (RFC 6901). Reads/writes referred values in JSON documents.
Readme
RFC 6901 JSON Pointer
JSON Pointer (RFC 6901) implementation in Dart.
Features:
- Reads, writes, removes values
- Fully implements the standard, including the
-character - Can build the entire path, e.g.
/foo/bar/-/baz - No external dependencies
- 100% test coverage
Constructing pointers
A JSON Pointer object can be parsed from a string expression. The expression MUST be a valid non-empty JSON Pointer expression with "/" and "~" escaped.
final pointer = JsonPointer('/foo/0/bar'); // a valid non-empty pointer
final alsoPointer = JsonPointer('/foo/-'); // a valid non-empty pointer with a special "-" reference
final emptyPointer = JsonPointer(); // an empty pointer
JsonPointer('oops'); // throws a FormatException: expression doesn't start with "/"
JsonPointer('/foo/~'); // throws a FormatException: unescaped "~"
It can also be built from individual reference tokens. In such case, it will escape the tokens automatically.
final pointer = JsonPointer.build(['foo', '0', 'bar/']); // Makes "/foo/0/bar~1"
final longerPointer = JsonPointerSegment('-', pointer); // Makes "/foo/0/bar~1/-"
final evenLongerPointer = JsonPointerSegment('wow', longerPointer); // Makes "/foo/0/bar~1/-/wow"
Reading and writing values
The read() method returns the referenced value. The write() method returns a copy of the document with
the referenced value replaced by the new value.
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');
[
'/foo', // reads the array
'/foo/0', // reads the first element of the array
'/foo/0/bar', // reads 42
].forEach((expression) {
final pointer = JsonPointer(expression);
print('Pointer "$pointer" reads ${pointer.read(document)}');
});
[
'/foo/0/bar', // {foo: [{bar: banana}]}
'/foo/-', // {foo: [{bar: 42}, banana]}
'/a/b/-/c/d', // {foo: [{bar: 42}], a: {b: [{c: {d: banana}}]}}
].forEach((expression) {
final pointer = JsonPointer(expression);
final d = pointer.write(document, 'banana');
print('Add a banana at "$pointer": $d');
});
}
Changelog
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning v2.
0.2.1 - 2025-10-16
Fixed
- Linter issues
0.2.0 - 2023-08-26
Changed
- Bump SDK to 3.0.0
0.1.1 - 2022-02-28
Added
Changed
- Updated dependencies
0.1.0 - 2021-02-18
Added
- Initial release
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'rfc_6901:0.2.1'pubspec.yaml
name: rfc_6901
version: 0.2.1
description: JSON Pointer (RFC 6901). Reads/writes referred values in JSON documents.
homepage: "https://github.com/f3ath/rfc-6901-dart"
environment:
sdk: '>=3.0.0 <4.0.0'
dev_dependencies:
lints: ^6.0.0
test: ^1.20.1
check_coverage: ^0.0.4
cider:
link_template:
tag: https://github.com/f3ath/rfc-6901-dart/releases/tag/%tag% # initial release link template
diff: https://github.com/f3ath/rfc-6901-dart/compare/%from%...%to% # subsequent releases link template
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.0-nullsafety.0 | Cached · Upstream SHA-256 matched | Download | 62d0a25e…a997ad |
| 0.0.0-nullsafety.1 | Cached · Upstream SHA-256 matched | Download | df232c0d…2ef772 |
| 0.0.0-nullsafety.2 | Cached · Upstream SHA-256 matched | Download | 3806f1cb…4fa476 |
| 0.0.0-nullsafety.3 | Cached · Upstream SHA-256 matched | Download | fe65754a…8c5980 |
| 0.0.0-nullsafety.4 | Cached · Upstream SHA-256 matched | Download | a7b867a5…c7c0ff |
| 0.0.0-nullsafety.5 | Cached · Upstream SHA-256 matched | Download | a99e5528…ce7b30 |
| 0.0.0-nullsafety.6 | Cached · Upstream SHA-256 matched | Download | 145f99b8…8f502d |
| 0.0.0-nullsafety.7 | Cached · Upstream SHA-256 matched | Download | c3d251bf…9fff53 |
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | 289b27ba…087159 |
| 0.1.1 | Cached · Upstream SHA-256 matched | Download | 8d97680d…32b988 |
| 0.2.0 | Cached · Upstream SHA-256 matched | Download | df1bbfa3…416820 |
| 0.2.1 | Cached · Upstream SHA-256 matched | Download | 6a43b185…018154 |
Dependencies
No direct dependencies declared.