Macro serde_json_lodash::nth[][src]

macro_rules! nth {
    () => { ... };
    ($a:expr $(,)*) => { ... };
    ($a:expr, $b:expr $(,)*) => { ... };
    ($a:expr, $b:expr, $($rest:tt)*) => { ... };
}

Description can be found in lodash nth

Examples:

#[macro_use] extern crate serde_json_lodash;
use serde_json::json;
let array = json!(['a', 'b', 'c', 'd']);
assert_eq!(
  nth!(array.clone(), 1),
  json!('b')
);
assert_eq!(
  nth!(array.clone(), -2),
  json!('c')
);

More examples:

assert_eq!(nth!(), json!(null));
assert_eq!(nth!(json!(null)), json!(null));
assert_eq!(nth!(json!(false)), json!(null));
assert_eq!(nth!(json!(true)), json!(null));
assert_eq!(nth!(json!(0)), json!(null));
assert_eq!(nth!(json!("")), json!(null));
assert_eq!(nth!(json!("ab")), json!("a"));
assert_eq!(nth!(json!("冬至")), json!("冬"));
assert_eq!(nth!(json!("夏至"), -1), json!("至"));
assert_eq!(nth!(json!("春分"), -3), json!(null));
assert_eq!(nth!(json!("秋分"), 2), json!(null));
assert_eq!(nth!(json!([])), json!(null));
assert_eq!(nth!(json!({})), json!(null));