dart_json_predicate 1.1.1

  • README.md
  • Example
  • Installing
  • Versions
  • 0

dart_json_predicate

A library for Dart which implements the JSON Predicate proposal: https://tools.ietf.org/id/draft-snell-json-test-01.html

Usage

A simple usage example:

import 'package:dart_json_predicate/json_predicate.dart' as jpredicate;

var testDocument = {
  "level1_0" : "This is a string value",
  "level1_1" : 5,
  "level1_2" : -3,
  "level1_3" : 3.2,
  "level1_4" : -2.2,
  "level1_5" : "2012-04-23T18:25:43.511Z",
  "level1_6" : ["Test 123", "abcdef"],
  "level1_7" : [5,6,7,8,9]
};

main() {
  var result = jpredicate.json(testDocument, {
    'op' : 'matches',
    'path' : '/level1_0',
    'value' : '[\\w\\s]*'
  });

  print(result);
}

Take a look at the test cases for more examples.

Features

All operators as specified in the proposal are available. Currently there is only support for the datatypes: string, number, boolean, array and undefined.

example/dart_json_predicate_example.dart

// Copyright (c) 2016, Andreas Reiter. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'package:dart_json_predicate/json_predicate.dart' as jpredicate;
import 'package:logging/logging.dart';

var testDocument = {
  "level1_0" : "This is a string value",
  "level1_1" : 5,
  "level1_2" : -3,
  "level1_3" : 3.2,
  "level1_4" : -2.2,
  "level1_5" : "2012-04-23T18:25:43.511Z",
  "level1_6" : ["Test 123", "abcdef"],
  "level1_7" : [5,6,7,8,9],

  "level1_c0" : {
    "level2c0_0" : "This is a string value",
    "level2c0_1" : 5,
    "level2c0_2" : -3,
    "level2c0_3" : 3.2,
    "level2c0_4" : -2.2,
    "level2c0_5" : "2012-04-23T18:25:43.511Z",
    "level2c0_6" : ["Test 123", "abcdef"],
    "level2c0_7" : [5,6,7,8,9],
  },

  "level1_c1" : {
    "level2c1_0" : {
      "level3c10" :{
        "level2c0_0" : "This is another string value",
        "level2c0_1" : 5,
        "level2c0_2" : -3,
        "level2c0_3" : 3.2,
        "level2c0_4" : -2.2,
        "level2c0_5" : "2013-04-23T18:25:43.511Z",
        "level2c0_6" : ["Test 123", "abcdef"],
        "level2c0_7" : [5,6,7,8,9]
      }
    }
  }
};

main() {
  Logger.root.level = Level.FINEST;
  Logger.root.onRecord.listen((LogRecord rec) {
    print('[${rec.loggerName}] ${rec.level.name}: ${rec.time}: ${rec.message}');
  });

  var result = jpredicate.json(testDocument, {
    'op' : 'matches',
    'path' : '/level1_0',
    'value' : '[\\w\\s]*'
  }, debug: true);
  print(result);
}

Use this package as a library

1. Depend on it

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


dependencies:
  dart_json_predicate: ^1.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:dart_json_predicate/json_predicate.dart';
  
Version Uploaded Documentation Archive
1.1.1 Jul 18, 2016 Go to the documentation of dart_json_predicate 1.1.1 Download dart_json_predicate 1.1.1 archive
1.1.0 Jul 18, 2016 Go to the documentation of dart_json_predicate 1.1.0 Download dart_json_predicate 1.1.0 archive
1.0.0 Jul 11, 2016 Go to the documentation of dart_json_predicate 1.0.0 Download dart_json_predicate 1.0.0 archive
0.0.1 Jul 11, 2016 Go to the documentation of dart_json_predicate 0.0.1 Download dart_json_predicate 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <2.0.0