parseSchemaFromString method

JsonSchema parseSchemaFromString(
  1. String jsonString
)

Parses a JSON Schema from a JSON string.

Returns a JsonSchema object representing the parsed schema. Throws FormatException if the string contains invalid JSON. Throws ArgumentError if jsonString is null or empty.

Implementation

JsonSchema parseSchemaFromString(String jsonString) {
  if (jsonString.isEmpty) {
    throw ArgumentError('JSON string cannot be empty');
  }

  try {
    final jsonData = json.decode(jsonString) as Map<String, dynamic>;
    return JsonSchema.fromJson(jsonData);
  } on FormatException catch (e) {
    throw FormatException('Invalid JSON string: ${e.message}');
  }
}