parseJsonWithBigInts function

Object? parseJsonWithBigInts(
  1. String json
)

Parses a JSON string, converting all integer values to BigInt.

Floating-point numbers (those containing a decimal point or a negative exponent) are preserved as double. All other numerical values are converted to BigInt to avoid precision loss with large integers.

This is a Dart port of the parseJsonWithBigInts function from the @solana/rpc-spec-types TypeScript package.

Implementation

Object? parseJsonWithBigInts(String json) {
  return jsonDecode(
    _wrapIntegersInBigIntValueObject(json),
    reviver: (key, value) {
      if (_isBigIntValueObject(value)) {
        return _unwrapBigIntValueObject(value! as Map<String, Object?>);
      }
      return value;
    },
  );
}