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

Related tags

Templates 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...

New trick on how to create your own custom icons in flutter with bottom bar navigation

New trick on how to create your own custom icons in flutter with bottom bar navigation

Customized Bottom Navigation Bar in Flutter | Tech With Sam Customized Bottom Navigation Bar in Flutter - Watch on youtube ✌   App Preview App Screens

Oct 26, 2022

Use the template to create your own repository, complete the project and verify

Use the template to create your own repository, complete the project and verify

Proyecto NivelaciΓ³n MisionTic Usar el template para crear un repositorio propio,

Dec 20, 2021

Destini flutter - A choose your own adventure game in flutter

Destini flutter - A choose your own adventure game in flutter

destini_flutter A choose your own adventure game made with flutter. Getting Star

Jan 2, 2022

Easily integrate GitHub's Octicons in your own Flutter project

flutter_octicons Use the Octicon icons developed by GitHub and released under the MIT license in Flutter. flutter_octicons automatically updates itsel

Nov 21, 2022

A Flutter add-to-app demo you can try with your own apps

A Flutter add-to-app demo you can try with your own apps

Put Flutter to Work 🏠 Hello! This project is a demo intended to help people test drive Flutter by integrating it into their existing applications. In

Jan 8, 2023

In this project, we will design a travel app UI with a parallax effect for a unique scroll experience. You will learn how to create your own parallax effect without using external libraries.

In this project, we will design a travel app UI with a parallax effect for a unique scroll experience. You will learn how to create your own parallax effect without using external libraries.

Travel App UI In this part, we will design a travel app UI with a parallax effect for a unique scroll experience. You will learn how to create your ow

Dec 5, 2022

ToDo App made with flutter which stores your todos based on their categories. The data is stored in external application storage in your device in JSON file.

ToDo App made with flutter which stores your todos based on their categories. The data is stored in external application storage in your device in JSON file.

⭐ My ToDo ⭐ Built with ❀︎ by Akash Debnath This is my second project on Flutter. This app hepls you to keep record of your ToDos. You can create your

Dec 25, 2022

As a beginner , this is my own side project by using flutter & dart , Firebase . This app still in progress .

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

Nov 23, 2021

Contribute in building the Ultimate GitBook of Developers by creating your git-card.json

Contribute in building the Ultimate GitBook of Developers by creating your git-card.json

Contribute in building the Ultimate GitBook of Developers by creating your git-card.json gitcards The Attractive and Interactive Variant of your GitHu

Apr 8, 2022
Releases(0.0.3)
Owner
FlutterQueen
FlutterQueen
A Dart validation DSL to validate your flutter app models.

Validations made simple A fp inspired validation DSL. For Dart and Flutter projects. Features Completely extensible (create your own combinators, vali

Daniel Cardona Rojas 26 Feb 8, 2022
Flutter package: Json Table Widget to create table from json array

Json Table Widget ?? Proudly Sponsored by FieldAssist Request a Demo This Flutter package provides a Json Table Widget for directly showing table from

Ayush P Gupta 193 Jan 7, 2023
State Persistence - Persist state across app launches. By default this library store state as a local JSON file called `data.json` in the applications data directory. Maintainer: @slightfoot

State Persistence Persist state across app launches. By default this library store state as a local JSON file called data.json in the applications dat

Flutter Community 70 Sep 28, 2022
Fluter-json - App Demonstrating JSON Data Parsing with various flutter widgets

users_list Flutter App to Demonstrate JSON Parsing Getting Started This project is a starting point for a Flutter application. A few resources to get

Khurram Rizvi 5 Jul 10, 2021
Json editor - A json editor on flutter

Features Support add comment; Support show errors for invalid json text; Pretty

Chan Young 12 Nov 18, 2022
Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON.

JSON to Dart Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON. This library is designed to ge

Javier Lecuona 1.2k Dec 25, 2022
Flashcard App where you can learn different topics and create your own flashcards in Google Drive.

flashcard_project Flashcard app connected with Google Spreadsheet Getting Started This is a Flutter Project that works on iOS, Android, Web and MacOS.

Max Weber 11 Oct 24, 2022
A library that makes it easy for you to create your own custom wizard.

Flutter Wizard Author: Jop Middelkamp A library that makes it easy for you to create your custom wizard. You'll have 100% control over the appearance

Baseflow 13 Dec 2, 2022
An extended version of Flutter Colors with more swatches and more flexibility to generate your own custom swatch.

Colours An extended version of Flutter Colors with more swatches and more flexibility to generate your own custom swatch. Getting Started In your flut

Salman S 4 Nov 23, 2021
Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter.

Official Flutter packages for Stream Chat Quick Links Register to get an API key for Stream Chat Flutter Chat SDK Tutorial Chat UI Kit Sample apps Thi

Stream 659 Dec 25, 2022