json_path 0.4.3 copy "json_path: ^0.4.3" to clipboard
json_path: ^0.4.3 copied to clipboard

retracted

Implementation of JSONPath expressions like "$.store.book[2].price". Reads and writes values in parsed JSON objects.

example/example.dart

import 'dart:convert';

import 'package:json_path/json_path.dart';

void main() {
  final document = 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:');

  prices
      .read(document)
      .map((match) => '${match.pointer}:\t${match.value}')
      .forEach(print);

  print('Books under 10:');

  JsonPath(r'$.store.book[?(@.price < 10)].title')
      .read(document)
      .map((match) => '${match.pointer}:\t${match.value}')
      .forEach(print);

  print("Books with letter 'a' in the author's name:");

  JsonPath(r'$.store.book[?author].title', filters: {
    'author': (match) {
      final author = match.value['author'];
      return author is String && author.contains('a');
    }
  })
      .read(document)
      .map((match) => '${match.pointer}:\t${match.value}')
      .forEach(print);
}
94
likes
0
pub points
99%
popularity

Publisher

verified publisherkarapetov.com

Implementation of JSONPath expressions like "$.store.book[2].price". Reads and writes values in parsed JSON objects.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

petitparser, rfc_6901

More

Packages that depend on json_path