Skip to content
/ jops Public

Rust serde_json::Value Operators

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

marshauf/jops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Operators

A collection of tools to help operate on serde_json::Values.

partial_cmp

JOPS provides a function for comparing two serde_json::Value.

Examples

The partial_cmp function.

use std::cmp::Ordering;
use serde_json::Value;

let a = Value::Null;
let b = Value::Null;
let res : Ordering = jops::partial_cmp(&a, &b);

JsonValue wrapper provides partial_cmp.

use jops;
use serde_json::Value;

let a = jops::JsonValue(&Value::Null);
let b = jops::JsonValue(&Value::Null);
let res = a > b;

JsonPath

An SQLite JSON Path implementation. Access Values inside an Object or Array.

Operators

  • $ represents the root Value
  • .<name> points to a sub value with key name inside an Object
  • <name>[<index>] points to a value inside an Array name at index (zero indexed).
  • <name>[#-<offset>] points to a value inside an Array name at length of array minus offset.
  • <index> points to a value inside a root Array at index (zero indexed).

Examples

let value = serde_json::json!({ "a": "example", "b": [0,1,2] });
value.path("$"); // Returns a reference to value
value.path("$.a"); // Returns a reference to the String value "example"
value.path("$.b[1]"); // Returns a reference to the Number value 1 inside the array b
value.path("$.b[#-1]"); // Returns a reference to the Number value 1 inside the array b
let value = serde_json::json!([0,2]);
value.path("1"); // Returns a reference to the Number value 2 inside the array

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

Rust serde_json::Value Operators

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages