JsonValue extension type

A zero-cost wrapper around any JSON value including null.

This type mostly exists to provide a common supertype for all JSON values, but otherwise has no behavior or properties of its own. To model an object that intentionally is unknown (could be any type of JSON value), see the JsonAny type (and asAny).

Safety

It is undefined behavior to cast (i.e. using as or a similar method such as List.cast) an Object to a JsonValue if it is not a valid JSON value.

For example, casting a Duration to a JsonValue fails during encoding:

import 'dart:convert';

import 'package:jsonut/jsonut.dart';

void main() {
  final value = Duration(seconds: 1);
  jsonEncode(value); // Throws
}

See also:

on
Implementers

Methods

asAny() JsonAny
Converts this object into a JsonAny.

Static Methods

parse<T extends JsonValue?>(String json) → T
Parses the given json string into a typed JSON value.
parseUtf8<T extends JsonValue?>(List<int> bytes) → T
Parses the given UTF-8 encoded bytes into a typed JSON value.