json_schema_matcher 1.0.0 copy "json_schema_matcher: ^1.0.0" to clipboard
json_schema_matcher: ^1.0.0 copied to clipboard

retracted

A Dart library for JSON schema validation using native testing framework matchers with strongly-typed validators and detailed error messages.

example/json_schema_matcher_example.dart

import 'package:json_schema_matcher/json_schema_matcher.dart';
import 'package:test/test.dart';

void main() {
  test('user validation', () {
    final userData = {
      'id': 1,
      'name': 'João Silva',
      'email': 'joao@email.com',
      'age': 30,
    };

    expect(
      userData,
      isJsonObject({
        'id': typeOf<int>(),
        'name': typeOf<String>(),
        'email': typeOf<String>(),
        'age': typeOf<int>(),
      }),
    );
  });

  test('user with optional fields', () {
    final userData = {
      'id': 1,
      'name': 'Maria Santos',
      'email': 'maria@email.com',
    };

    expect(
      userData,
      isJsonObject({
        'id': typeOf<int>(),
        'name': typeOf<String>(),
        'email': typeOf<String>(),
        'phone': typeOf<String?>(), // optional field
      }),
    );
  });

  test('array of users', () {
    final users = [
      {'id': 1, 'name': 'Alice'},
      {'id': 2, 'name': 'Bob'},
    ];

    expect(
      users,
      isJsonArray({
        'id': typeOf<int>(),
        'name': typeOf<String>(),
      }),
    );
  });

  test('array of strings', () {
    expect(
      ['dart', 'json', 'validation'],
      isJsonArrayOf<String>(),
    );
  });

  test('nested object', () {
    final data = {
      'user': {
        'id': 1,
        'name': 'Pedro',
        'profile': {
          'firstName': 'Pedro',
          'lastName': 'Costa',
        },
      },
    };

    expect(
      data,
      isJsonObject({
        'user': jsonObject({
          'id': typeOf<int>(),
          'name': typeOf<String>(),
          'profile': jsonObject({
            'firstName': typeOf<String>(),
            'lastName': typeOf<String>(),
          }),
        }),
      }),
    );
  });
}
2
likes
0
points
76
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart library for JSON schema validation using native testing framework matchers with strongly-typed validators and detailed error messages.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

test

More

Packages that depend on json_schema_matcher