Module assign

Source
Expand description

§Assign values based on JSON Pointers

This module provides the Assign trait which allows for the assignment of values based on a JSON Pointer.

This module is enabled by default with the "assign" feature flag.

§Expansion

The path will automatically be expanded if the Pointer is not fully exhausted before reaching a non-existent key in the case of objects, index in the case of arrays, or a scalar value (including null) based upon a best-guess effort on the meaning of each Token:

  • If the Token is equal to "0" or "-", the token will be considered an index of an array.
  • All tokens not equal to "0" or "-" will be considered keys of an object.

§Usage

Assign can be used directly or through the assign method of Pointer.

use jsonptr::Pointer;
use serde_json::json;
let mut data = json!({"foo": "bar"});
let ptr = Pointer::from_static("/foo");
let replaced = ptr.assign(&mut data, "baz").unwrap();
assert_eq!(replaced, Some(json!("bar")));
assert_eq!(data, json!({"foo": "baz"}));

§Provided implementations

Langvalue typefeature flagDefault
JSONserde_json::Value"json"
TOMLtoml::Value"toml"

Enums§

Error
Possible error returned from Assign implementations for serde_json::Value and toml::Value.

Traits§

Assign
Implemented by types which can internally assign a (Value) at a path represented by a JSON Pointer.

Type Aliases§

AssignErrorDeprecated
Alias for Error - indicates a value assignment failed.