json_bigint 2.0.0 copy "json_bigint: ^2.0.0" to clipboard
json_bigint: ^2.0.0 copied to clipboard

A json serializer for dart that supports BigInt.

example/main.dart

import 'package:json_bigint/json_bigint.dart';

void printObj(String key, Object? val) =>
    print("$key is of type ${val.runtimeType} and has value: $val.");

void main() {
  String json = '''{
          "sometext": "hello world!",
          "bignumber": 999999999999999999,
          "expnumber": 2e3
        }''';

  print("Decoding:");
  print("------------------------");
  final jsonMap = decodeJson(json) as Map<String, Object?>;
  printObj("sometext", jsonMap["sometext"]);
  printObj("bignumber", jsonMap["bignumber"]);
  printObj("expnumber", jsonMap["expnumber"]);

  print("\nDecoding w/ settings:");
  print("------------------------");
  final decSettings = DecoderSettings(
    useIntWhenPossible: true,
    treatExpAsIntWhenPossible: true,
  );
  final jsonMap2 = decodeJson(
    json,
    settings: decSettings,
  ) as Map<String, Object?>;
  printObj("bignumber", jsonMap2["bignumber"]);
  printObj("expnumber", jsonMap2["expnumber"]);

  print("\nEncoding:");
  print("------------------------");
  String jsonNew = encodeJson(jsonMap);
  print(jsonNew);

  print("\nEncoding w/ Settings:");
  print("------------------------");
  final encSettings = EncoderSettings(
    indent: "  ",
    singleLineLimit: 30,
    afterKeyIndent: " ",
  );
  String jsonFormatted = encodeJson(jsonMap2, settings: encSettings);
  print(jsonFormatted);
}
2
likes
130
points
288
downloads

Publisher

unverified uploader

Weekly Downloads

A json serializer for dart that supports BigInt.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

BSD-3-Clause (license)

Dependencies

collection, meta, petitparser

More

Packages that depend on json_bigint