json_validator 0.5.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 49

json_validator

A library for Dart developers. Its purpose is to validate json data structures. The data structure is modelled using Validator objects. Then the json data structure can be validated. Missing fields are identified and can optionally be replaced with a default value. Fields of the wrong type are identified and removed from the validated object.

Usage

A simple usage example:

import 'package:json_validator/type_validator.dart';

main() {
  var personMap = {"name":"sarah", "age":40, "hasLongHair":false};

  var personValidator = new MapValidator({
    "age":new MapField(INT),
    "name":new MapField(STRING),
    "hasLongHair":new MapField(BOOL, defaultValue:false),
    "likesIceCream":new MapField(BOOL, defaultValue:true),
  });

  print(personValidator.validate(personMap));
  print(personValidator.errors);
}

Please see the test file for more usage examples.

dependencies

A library to check cross-dependencies in json maps. Classes and methods in this library can verify that keys or values at one location in a map are also present at other locations. Consider a map containing a list of orders and and list of products. the orders contain productIds. These can be checked to see if they are present in the product list.

Usage:

A simple usage example:

import 'package:json_validator/dependencies.dart';

var map = {
  "orders": {
    "order0001": {
      "products": {
        "product001": {
          "amount": 3,
          "options": {
            "option001":"option001val001"
          }
        }
      }
    }
  },
  "products": {
    "product001": {
      "options": {
        "option001": {
          "option001val001":"blue",
          "option001val002":"red"
        }
      }
    }
  }
};

main() {
  var sourceTemplate = new SourceTemplate(["orders", "*", "products", "*", "options", "*"], true);
  var locationTemplate = new LocationTemplate(["products", "#1", "options", "#2", "VAL"], null);

  var sourceList = new SourceList.fromMapAndSourceTemplate(map, sourceTemplate);
  var locationList = new LocationList.fromSourceListAndTemplate(sourceList, locationTemplate);

  var verifiedLocationList = locationList.validateWithMap(map);
  print(verifiedLocationList);
} 

Features and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.0.1

  • Initial version, created by Stagehand

0.1.0

  • Changed syntax to allow simpler composition

0.2.0

  • Changed validation of simple types to static instances. Added object validation framework

0.2.1

  • Updated documentation

0.2.2

  • bug fix

0.3.1

  • implemented finer grained control of validation of map fields

0.4.0

  • moved all logic that effects map fields to the map field constructor

0.5.1

  • changed object builder argument to dynamic to allow building of objects from simple values

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  json_validator: "^0.5.1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:json_validator/dependencies.dart';

      import 'package:json_validator/type_validator.dart';
  
Version Uploaded Documentation Archive
0.5.1 Oct 22, 2017 Go to the documentation of json_validator 0.5.1 Download json_validator 0.5.1 archive
0.5.0 Oct 19, 2017 Go to the documentation of json_validator 0.5.0 Download json_validator 0.5.0 archive
0.4.0 Oct 17, 2017 Go to the documentation of json_validator 0.4.0 Download json_validator 0.4.0 archive
0.3.0 Oct 15, 2017 Go to the documentation of json_validator 0.3.0 Download json_validator 0.3.0 archive
0.2.2 Oct 14, 2017 Go to the documentation of json_validator 0.2.2 Download json_validator 0.2.2 archive
0.2.1 Oct 14, 2017 Go to the documentation of json_validator 0.2.1 Download json_validator 0.2.1 archive
0.2.0 Oct 14, 2017 Go to the documentation of json_validator 0.2.0 Download json_validator 0.2.0 archive
0.1.0 Oct 13, 2017 Go to the documentation of json_validator 0.1.0 Download json_validator 0.1.0 archive
0.0.1 Oct 12, 2017 Go to the documentation of json_validator 0.0.1 Download json_validator 0.0.1 archive

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
98 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
49
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 11 hints.

    Run dartfmt to format lib/dependencies.dart.

    Run dartfmt to format lib/src/dependencies/location.dart.

    Similar analysis of the following files failed:

    • lib/src/dependencies/location_list.dart (hint)
    • lib/src/dependencies/location_template.dart (hint)
    • lib/src/dependencies/location_validator.dart (hint)
    • lib/src/dependencies/source.dart (hint)
    • lib/src/dependencies/source_list.dart (hint)
    • lib/src/dependencies/source_template.dart (hint)
    • lib/src/type_validator/object_builder.dart (hint)
    • lib/src/type_validator/type_validator_base.dart (hint)
    • lib/src/type_validator/type_validator_helpers.dart (hint)
  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use json_validator.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
Dev dependencies
test ^0.12.0