g_json 4.1.1 copy "g_json: ^4.1.1" to clipboard
g_json: ^4.1.1 copied to clipboard

g_json makes it easy to get&set value from JSON data in dart2.

example/lib/main.dart

// ignore: avoid_relative_lib_imports
import '../../lib/g_json.dart';

void main(List<String> args) {
  final jsonStr = '''
  {
    "_id": "5f0fd54e54044a55385a0f31",
    "name": {
      "first": "Coleman",
      "last": "Evans"
    },
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Gibson Hull"
      },
      {
        "id": 1,
        "name": "Dunlap Bush"
      },
      {
        "id": 2,
        "name": "Bette Herman"
      }
    ]
  }
  ''';

  final j = JSON.parse(jsonStr);
  print(j.toString());
  print(j.prettyString());

  final _id = j['_id'].stringValue;
  print('_id: $_id');

  final lastName = j[['name', 'last']].stringValue;
  print('name.last: $lastName');

  final r3 = j['range'][3].number ?? -1;
  print('range:3 $r3');

  final friends = j['friends'].listValue;
  print('friends: $friends');

  final value = j.value;
  print('value: $value');

  print('---------------------');
  ////
  ///
  final nj = JSON({'a': 'a', 'b': 1});

  nj['b'] = null;

  print(nj.rawString());

  // dynamic member
  dynamic dj = nj;

  print(dj.a);
}
14
likes
160
points
587
downloads

Publisher

verified publisherfaraday.icu

Weekly Downloads

g_json makes it easy to get&set value from JSON data in dart2.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on g_json