validate JSON against your own Blueprint πŸ‘‘πŸ§¬

Overview

PART OF QUEEN πŸ‘‘

Validate JSON Against Your Own Blueprint πŸ‘‘ 🧬

example

Content

Motivation

we use json almost every day in our job with null safety we can skip many errors but we cant test if the api still intact after each update,

and the update does't break any thing in the data type or schema

so we meade this package mostly you can use it for testing the apis you consume with dart or what you built with dart we could use some help if you are interested in server side dart at palace project hope your day is bug-less with this package πŸ’™

NOTE

this package depends on dart >= 2.13.0 if you want to use it with flutter

you have to update to flutter >= 2.5

Features

  • validate json to match any schema you want 🌟
  • support dart native types πŸ”
  • support for TypeOrNull
  • support for .of for deeper and deeper validation πŸ’ͺ
  • throw or return false as a result πŸ’£
  • Strong Types , also the blueprint is just a map but values must be a subtype of BluePrintField which is all of supported types null or not
  • tells you which key is a failure and why πŸ’ͺ
  • tested πŸ§ͺ

supported types

data type non-nullable Field nullable Field
String StringF StringOrNull
int IntF IntOrNull
double DoubleF DoubleOrNull
num NumF NumOrNull
bool BoolF BoolOrNull
Map MapF MapOrNull
List ListF ListOrNull

Notes

1 - use matchMap Or matchF to get true or false as result

2 - set the throwable parameter to true to throw the error in case of miss match

3 - use .of() function on Map and List it is available on there four rules MapF,MapOrNull,ListF , ListOrNull to validate deer inside the object

4 - in case of null value the nullable Field Rule will not validate against the args an consider it a match

5 - in case of a value in the nullable Field Rule the .of() function will validate against the args and return the result based on that

Examples

example 1

import 'package:blueprint/blueprint.dart';

void main(List<String> arguments) {
  //* use try/catch blocs to catch the failure message
  try {
    // simple one felid
    matchMap(
      // the json
      {'name': 'queen'},
      // the blue print
      {'name': String},
      // * you can use supported Felids only , they are listen in the readme.md file
     throwable:true,

    );
    print('[πŸ‘‘][blue_print] match result is βœ…');
  } catch (e) {
    print(e);
    print('[πŸ‘‘][blue_print] match result is ❌');
  }
}

example 2

void main(List<String> arguments) {
  //* use try/catch blocs to catch the failure message
  try {

    // ? validate against lists
    matchMap(
      {
        'ids': [10, 11, 17]
      },
      {
        'ids': ListF,
        // ? or you can determine the list items type
        // 'ids' : ListF(IntF()),
      },
      throwable:true,

    );
    print('[πŸ‘‘][blue_print] match result is βœ…');
  } catch (e) {
    print(e);
    print('[πŸ‘‘][blue_print] match result is ❌');
  }
}

example 3

void main(List<String> arguments) {
  //* use try/catch blocs to catch the failure message
  try {

    // * full example
    matchMap(
      {
        'name': 'ahmed',
        'age': 25,
        'args': [
          {'foo': 5},
        ],
        'passport': {
          'id': 1,
          'type': 'royal',
          'created_at': '10-11-17',
        }
      },

      // the blue print
      {
        'name': StringF,
        'age': IntF,
        'args': ListF(MapF.of({'foo': IntF})),
        'passport': MapF.of({
          'id': IntF,
          'type': StringF,
          'created_at': StringF,
        })
      },
      throwable:true,
    );
    print('[πŸ‘‘][blue_print] match result is βœ…');
  } catch (e) {
    print(e);
    print('[πŸ‘‘][blue_print] match result is ❌');
  }
}
You might also like...

A Completed Functional Flutter App - FindSeat (BLoC + Json API + Unit Test + Firebase Auth)

A Completed Functional Flutter App - FindSeat (BLoC + Json API + Unit Test + Firebase Auth)

A Completed Functional Flutter App - FindSeat (BLoC + Json API + Unit Test + Firebase Auth) I. Introduction I’m Android Developer and I’m working in a

Jan 6, 2023

WeatherApp - A Weather App using json api And Flutter

WeatherApp - A Weather App using json api And Flutter

Weather App Bu uygulamda json api kullanarak bir WeatherApp yaptΔ±m. State Manage

Oct 12, 2022

A Completed Functional Flutter App - FindSeat (BLoC + Json API + Unit Test + Firebase Auth)

 A Completed Functional Flutter App - FindSeat (BLoC + Json API + Unit Test + Firebase Auth)

A Completed Functional Flutter App - FindSeat (BLoC + Json API + Unit Test + Firebase Auth) II. Showcase 2.1. Home In Home screen, it just simply load

Dec 6, 2022

A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

WhatTodo Life can feel overwhelming. But it doesn’t have to. A Simple To-do app design in flutter to keep track of your task on daily basis. You can a

Jan 6, 2023

A mobile image uploader in which you can upload image to your personal gallery from either your camera or mobile gallery and it can detect your current geographic location and address using firebase firestore and storage.

Image Uploader In Flutter About It is an Image Uploader gallery which tracks your address from which you're uploading using Flutter and Image picker.

Dec 20, 2022

Movie Lib is a mobile application where you can find the movies of your interest. This app provides a collection of movies of different languages according to your interest.

Movie Lib is a mobile application where you can find the movies of your interest. This app provides a collection of movies of different languages according to your interest.

Movie Lib Movie Lib is a mobile application where you can find the movies of your interest. This app provides a collection of movies of different lang

Sep 28, 2021

A simple easy to use Flutter DApp , which keeps a track of all your day to day transactions by using Ethereum blockchain in the background which in turn increases your credit score.

A simple easy to use Flutter DApp , which keeps a track of all your day to day transactions by using Ethereum blockchain in the background which in turn increases your credit score.

Sahayog A simple easy to use Flutter DApp , which keeps a track of all your day to day transactions by using Ethereum blockchain in the background whi

May 21, 2022

Your grades across all your devices.

Your grades across all your devices.

Gradely 2 A Grade Calculator App, that syncs all your Grades across all your devices, built with Flutter and with the amazing backend Appwrite. Screen

Dec 8, 2022

About This is Personal Expenses Planner. You can add your expenses in to the app and manage your transaction. and you can see How much did you spend on which day. I developed this project using flutter.

expense_planner A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Jul 6, 2022
Releases(0.0.3)
Owner
Ahmed Masoud
Ahmed Masoud
An open source encrypted peer-to-peer system. Own data, own privacy. (Rust+Flutter)

An open source encrypted peer-to-peer system. Own data, own privacy. (Rust+Flutter)

Cymple Tech 124 Oct 7, 2021
Encrypted peer-to-peer system for data security. Own data, own privacy

ESSE (Encrypted Symmetrical Session Engine) An open source encrypted peer-to-pee

CympleTech 455 Dec 26, 2022
Stream Feed official Flutter SDK. Build your own feed experience using Dart and Flutter.

Official Flutter packages for Stream Activity Feeds The official Dart client for Stream Activity Feeds, a service for building activity feed applicati

Stream 67 Sep 26, 2022
Pensil Community official Flutter SDK. Build your own community experience using Dart and Flutter.

Official flutter package for Pensil The official Dart client for Pensil communities, a service for building communites applications. This library can

Pensil Inc 6 Oct 6, 2022
A discord bot, made with Dart, which lets you run your own pure Dart code snippets directly via a discord ping, and get the output in an instant.

A discord bot, made with Dart, which lets you run your own pure Dart code snippets directly via a discord ping, and get the output in an instant.

Anikate De 3 Oct 21, 2022
This design has been created for educational purposes. Also this project has integrated push notifications with firebase and my own server in python.

Ui Clone of the Nequi application This design has been created for educational purposes. Also this project has integrated push notifications with fire

Juan Suarez 3 Nov 17, 2022
The application helps the patient to follow up on medication schedules, and each patient has his own profile. The application is connected to Bluetooth to help the patient's dependents follow up on the patient.

spoon_medicines A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

null 0 Nov 27, 2021
My flutter projects work with JSON

Apps work with JSON A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

Samandar 1 Oct 21, 2021
A widget to show json object

flutter_json_widget A Json viewer widget for flutter. Using the library The /example/ folder in the GitHub repo contains a full Flutter app with demo

demdog 25 Dec 28, 2021
Fluttermobile - Flutter Movie App Using BLoc Pattern and JSON API

Flutter Movie App Using BLoc Pattern and JSON API. Data Provider: https://www.th

BEŞİR Γ–ZTEN 5 Jul 6, 2022