Validate JSON against your own Blueprint

Validate JSON against your own Blueprint

PART OF QUEEN 👑

Validate JSON Against Your Own Blueprint 👑🧬

Validate JSON against your own Blueprint

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 ❌');
  }
}

GitHub

View Github

Leave a Reply

Your email address will not be published. Required fields are marked *

Instagram

Why do People Say: "Developers are Lazy"?
The saying “work smart, not hard” is applicable for programmers.
.
https://hackernoon.com/why-do-people-say-developers-are-lazy

.
Author: Aga Wozniak
.
.
.
.
.
#blog #100Daysofcode #javascript #vuejs #datascientist #peoplewhocode #learntocode #coding #developerlife #frontenddeveloper #backenddeveloper #fullstackdeveloper #developer #webdeveloper #thedevlife #phpdeveloper #computerscience #programmer #programmingisfun #codingdays
...

Mitigating the DDOS Threats Facing Banks and Fintechs
As much as digitization and cyber simplified banking, the Fintech sector has left digital payment activity exposed to malicious and suspicious activity.
.
https://hackernoon.com/mitigating-the-ddos-threats-facing-banks-and-fintechs

.
Author: Josh Horowitz
.
.
.
.
.
#blog #100Daysofcode #javascript #vuejs #datascientist #peoplewhocode #learntocode #coding #developerlife #frontenddeveloper #backenddeveloper #fullstackdeveloper #developer #webdeveloper #thedevlife #phpdeveloper #computerscience #programmer #programmingisfun #codingdays
...

24 Best JavaScript Blogs and Websites
In this overview, we have compiled a list of popular sites, as well as JS blogs that are worth reading and keeping in your bookmarks.
.
https://hackernoon.com/24-best-javascript-blogs-and-websites

.
Author: natashatsybliyenko
.
.
.
.
.
#blog #100Daysofcode #javascript #vuejs #datascientist #peoplewhocode #learntocode #coding #developerlife #frontenddeveloper #backenddeveloper #fullstackdeveloper #developer #webdeveloper #thedevlife #phpdeveloper #computerscience #programmer #programmingisfun #codingdays
...

The Projects Working to Lower Ethereum Gas Fees
As more investors try their hand at DeFi, gas fees are shooting over the roof, making engaging with decentralized apps uneconomical for most users.
.
https://hackernoon.com/ethereum-gas-fees-are-there-any-projects-working-to-optimize-eth-gas-fees

.
Author: CryptoVirally SLR
.
.
.
.
.
#blog #100Daysofcode #javascript #vuejs #datascientist #peoplewhocode #learntocode #coding #developerlife #frontenddeveloper #backenddeveloper #fullstackdeveloper #developer #webdeveloper #thedevlife #phpdeveloper #computerscience #programmer #programmingisfun #codingdays
...

On the Edge of a New Year: IT Predictions for 2022
The single biggest cause of network errors are people.
.
https://hackernoon.com/an-interview-with-uplogix-ceo-lisa-frankovitch

.
Author: Mignonette Garnier
.
.
.
.
.
#blog #100Daysofcode #javascript #vuejs #datascientist #peoplewhocode #learntocode #coding #developerlife #frontenddeveloper #backenddeveloper #fullstackdeveloper #developer #webdeveloper #thedevlife #phpdeveloper #computerscience #programmer #programmingisfun #codingdays
...

How to Modernize IBM i Applications
If you’re like most IBM i users, you know how much value your IBM i data and applications bring to your business. Your end-users, however, may not. In today’s world of rich user experience, fast-paced application development, and constantly evolving customer expectations, IBM i applications are unde…
.
https://hackernoon.com/how-to-modernize-ibm-i-applications

.
Author: Lansa
.
.
.
.
.
#blog #100Daysofcode #javascript #vuejs #datascientist #peoplewhocode #learntocode #coding #developerlife #frontenddeveloper #backenddeveloper #fullstackdeveloper #developer #webdeveloper #thedevlife #phpdeveloper #computerscience #programmer #programmingisfun #codingdays
...