All Projects → f3ath → jessie

f3ath / jessie

Licence: MIT license
JsonPath for Dart

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to jessie

JSONPath.sh
JSONPath implementation in Bash for filtering, merging and modifying JSON
Stars: ✭ 45 (+95.65%)
Mutual labels:  jsonpath
ctxexp-parser
In the dynamic execution of JS language environment (wechat applet) to execute JS class calling function.
Stars: ✭ 17 (-26.09%)
Mutual labels:  jsonpath
robotframework-jsonvalidator
Robot Framework library for JSON validation
Stars: ✭ 21 (-8.7%)
Mutual labels:  jsonpath
json-path-comparison
Comparison of the different implementations of JSONPath and language agnostic test suite.
Stars: ✭ 64 (+178.26%)
Mutual labels:  jsonpath
fs2-data
streaming data parsing and transformation library
Stars: ✭ 103 (+347.83%)
Mutual labels:  jsonpath
jsonpath
No description or website provided.
Stars: ✭ 117 (+408.7%)
Mutual labels:  jsonpath
ajson
Abstract JSON for Golang with JSONPath support
Stars: ✭ 144 (+526.09%)
Mutual labels:  jsonpath
yamlpath
Command-line get/set/merge/validate/scan/convert/diff processors for YAML/JSON/Compatible data using powerful, intuitive, command-line friendly syntax.
Stars: ✭ 78 (+239.13%)
Mutual labels:  jsonpath
json matcher
Library for simplifying data verification in functional tests for your JSON-based APIs
Stars: ✭ 24 (+4.35%)
Mutual labels:  jsonpath
json
Useful functions when working with JSON.
Stars: ✭ 17 (-26.09%)
Mutual labels:  json-path
rust-ajson
Rust port of gjson,get JSON value by dotpath syntax
Stars: ✭ 85 (+269.57%)
Mutual labels:  json-path
SwiftPath
JSONPath for Swift
Stars: ✭ 46 (+100%)
Mutual labels:  jsonpath
JPStream
JPStream: JSONPath Stream Processing in Parallel
Stars: ✭ 19 (-17.39%)
Mutual labels:  jsonpath
LBDuoDian
No description or website provided.
Stars: ✭ 21 (-8.7%)
Mutual labels:  jsonpath
xapi-profiles
A set of documents addressing the structure of and supporting services for xAPI Profiles.
Stars: ✭ 47 (+104.35%)
Mutual labels:  jsonpath
SMJJSONPath
JSONPath implementation in Objective-C
Stars: ✭ 28 (+21.74%)
Mutual labels:  jsonpath
mapneat
MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJO to JSON in a declarative way.
Stars: ✭ 45 (+95.65%)
Mutual labels:  jsonpath
web-data-extractor
Extracting and parsing structured data with jQuery Selector, XPath or JsonPath from common web format like HTML, XML and JSON.
Stars: ✭ 52 (+126.09%)
Mutual labels:  jsonpath
JsonPathKt
A lighter and more efficient implementation of JsonPath in Kotlin
Stars: ✭ 37 (+60.87%)
Mutual labels:  jsonpath
jsonuri
🌳 阿里剑鱼、iceluna、vanex 数据操作底层库,使用O(n) 复杂度回溯祖先节点
Stars: ✭ 131 (+469.57%)
Mutual labels:  jsonpath

JSONPath for Dart

import 'dart:convert';

import 'package:json_path/json_path.dart';

void main() {
  final json = jsonDecode('''
{
  "store": {
    "book": [
      {
        "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      {
        "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      },
      {
        "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      {
        "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}  
  ''');

  final prices = JsonPath(r'$..price');

  print('All prices in the store:');

  /// The following code will print:
  ///
  /// $['store']['book'][0]['price']:	8.95
  /// $['store']['book'][1]['price']:	12.99
  /// $['store']['book'][2]['price']:	8.99
  /// $['store']['book'][3]['price']:	22.99
  /// $['store']['bicycle']['price']:	19.95
  prices
      .read(json)
      .map((match) => '${match.path}:\t${match.value}')
      .forEach(print);
}

Limitations

This library is intended to match the original implementations, although filtering expressions (like $..book[?(@.price < 10)]) support is limited and may not always produce the results that you expect. The reason is the difference between the type systems of Dart and JavaScript/PHP. Dart is strictly typed and does not support eval(), so the expressions have to be parsed and evaluated by the library itself. Implementing complex logic this way would create a performance overhead which I prefer to avoid.

Callback filters

If there is a real need for complex filtering, you may use Dart-native callbacks. The syntax, which is of course my own invention and has nothing to do with the "official" JSONPath, is the following:

/// Selects all elements with price under 20
final path = JsonPath(r'$.store..[?discounted]', filters: {
'discounted': (match) =>
    match.value is Map && match.value['price'] is num && match.value['price'] < 20
});

The filtering callbacks may be passed to the JSONPath constructor or to the .read() method. The callback name must be specified in the square brackets and prefixed by ?. It also must be alphanumeric.

Data manipulation

Each JsonPathMatch produced by the .read() method contains the .pointer property which is a valid JSON Pointer and can be used to write/append/remove the referenced value. If you're looking for data manipulation only, take a look at this JSON Pointer implementation.

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].