json_by_path 1.0.1 copy "json_by_path: ^1.0.1" to clipboard
json_by_path: ^1.0.1 copied to clipboard

Get, Set, create, delete Json Maps using path relative keys. No dependencies, as simple as possible!

example/json_by_path_example.dart

import 'dart:convert';

import 'package:json_by_path/json_by_path.dart';

void main() {
  Map<String, dynamic> _json = {
    'key 1': 'value 1',
    'key 2': 'value 2',
    'key 3': {
      'key 3_1': <String, dynamic>{'key 3_1_1': 'value 3.1.1'}
    },
    'key 4': {
      'key 4.1': {'key 4.1.1': 'value 4.1.1'}
    },
    'key 5': 4,
    'key 6': true,
    'key 7': <String>['value 7_1', 'value 7_2', 'value 7_3']
  };

  JsonByPath jbp = JsonByPath();
//  _json = json.decode(json.encode(_json));

  print(jbp.getValue(_json, null));
  print(jbp.getValue(_json, 'key 3.key 3_1'));
  jbp.setValue(_json, 'key 3.key 3_1.key 3_1_1', 4);
  jbp.setValue(_json, 'key 3.key 3_1.key 3_1_2.key 3_1_2_a', 4);
  print(jbp.getValue(_json, 'key 3.key 3_1'));

  print(jbp.getValue(_json, 'key 2'));
  print(List<String>.from(jbp.getValue(_json, 'key 7')));
}
4
likes
150
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

Get, Set, create, delete Json Maps using path relative keys. No dependencies, as simple as possible!

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on json_by_path