agent-first-data 0.29.0

A naming convention that lets AI agents understand your data without being told what it means, plus a CLI and library for reading Markdown structure and safely editing structured JSON, TOML, YAML, dotenv, and INI documents.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
//! Core dot-path traversal for get/set operations.

use crate::document::{
    DocumentError, DocumentResult, Value,
    keyed::{Addressing, KeyedList},
    path::{join_path, parse_path},
};

/// Resolve one non-numeric segment against `array`, returning the index of the
/// single element it names.
///
/// Shared by the read and write walks so both answer a given address the same
/// way — and so the refusals stay in one place: an array nothing claims is
/// [`DocumentError::UnregisteredArray`], no match is
/// [`DocumentError::SlugNotFound`], and several matches is
/// [`DocumentError::AmbiguousMatch`] rather than the first one.
fn resolve_named_element(
    array: &[Value],
    segment: &str,
    prefix: &[String],
    addressing: Addressing<'_>,
) -> DocumentResult<usize> {
    // A caller's explicit declaration outranks a format-wide rule: it names one
    // array on purpose, so it is the more specific statement about this one.
    if let Some(registration) = addressing
        .keyed_lists
        .iter()
        .find(|list| keyed_prefix_matches(list, prefix))
    {
        let hits = array
            .iter()
            .enumerate()
            .filter(|(_, element)| {
                element.get(registration.slug_field).and_then(Value::as_str) == Some(segment)
            })
            .map(|(index, _)| index)
            .collect();
        return resolve_unique_hit(hits, segment, &join_path(prefix));
    }

    let Some(rule) = addressing.array_rule else {
        return Err(DocumentError::UnregisteredArray {
            path: join_path(prefix),
        });
    };

    let hits: Vec<usize> = array
        .iter()
        .enumerate()
        .filter(|(_, element)| rule.matches(element, segment))
        .map(|(index, _)| index)
        .collect();
    resolve_unique_hit(hits, segment, &join_path(prefix))
}

fn resolve_unique_hit(hits: Vec<usize>, segment: &str, prefix: &str) -> DocumentResult<usize> {
    match hits.as_slice() {
        [] => Err(DocumentError::SlugNotFound {
            prefix: prefix.to_string(),
            slug: segment.to_string(),
        }),
        [only] => Ok(*only),
        several => Err(DocumentError::AmbiguousMatch {
            prefix: prefix.to_string(),
            segment: segment.to_string(),
            indices: several.to_vec(),
        }),
    }
}

/// Parse an array index without letting decimal overflow fall through to named
/// lookup.
///
/// `str::parse::<usize>()` alone cannot distinguish "not a number" from "a
/// number too large for this platform". The former may be a slug; the latter
/// is still lexically an index and must fail as one rather than unexpectedly
/// matching document content.
fn array_index(segment: &str) -> DocumentResult<Option<usize>> {
    if segment.is_empty() || !segment.bytes().all(|byte| byte.is_ascii_digit()) {
        return Ok(None);
    }
    segment
        .parse::<usize>()
        .map(Some)
        .map_err(|_| DocumentError::PathSyntax {
            detail: "array index exceeds the platform index range".to_string(),
        })
}

/// Get a value at the given dot-path.
///
/// Handles:
/// - Object field access (any level of nesting)
/// - Named array access (keyed-list slug, or a format's own array rule)
/// - Greedy key matching for keys containing '.'
pub fn get_path_ref<'a>(
    root: &'a Value,
    path: &str,
    addressing: Addressing<'_>,
) -> DocumentResult<&'a Value> {
    if path.is_empty() {
        return Err(DocumentError::EmptyPath);
    }

    let segments = parse_path(path)?;
    let mut current = root;
    let mut accumulated_prefix: Vec<String> = Vec::new();
    let mut seg_idx = 0;

    while seg_idx < segments.len() {
        let current_seg = segments[seg_idx].as_str();

        match current {
            Value::Object(obj) => {
                // Try exact match first
                if let Some(next) = obj.get(current_seg) {
                    accumulated_prefix.push(current_seg.to_string());
                    current = next;
                    seg_idx += 1;
                } else {
                    return Err(DocumentError::UnknownSegment {
                        path: path.to_string(),
                        segment: current_seg.to_string(),
                    });
                }
            }
            Value::Array(arr) => {
                // Numeric index takes priority over keyed-list slug.
                if let Some(arr_idx) = array_index(current_seg)? {
                    let elem = arr
                        .get(arr_idx)
                        .ok_or_else(|| DocumentError::IndexOutOfBounds {
                            path: join_path(&accumulated_prefix),
                            index: arr_idx,
                            len: arr.len(),
                        })?;
                    accumulated_prefix.push(current_seg.to_string());
                    current = elem;
                    seg_idx += 1;
                } else {
                    let index =
                        resolve_named_element(arr, current_seg, &accumulated_prefix, addressing)?;
                    current = &arr[index];
                    accumulated_prefix.push(current_seg.to_string());
                    seg_idx += 1;
                }
            }
            _ => {
                return Err(DocumentError::NotTraversable {
                    path: path.to_string(),
                    got: current.kind_name().to_string(),
                });
            }
        }
    }

    Ok(current)
}

/// Get a cloned value at the given dot-path.
pub fn get_path(root: &Value, path: &str, addressing: Addressing<'_>) -> DocumentResult<Value> {
    Ok(get_path_ref(root, path, addressing)?.clone())
}

/// Rewrite `path` into the equivalent index-only address for `root`.
///
/// Content addressing is something only the parsed value can answer, and the
/// source-preserving writers never see it: each backend re-walks the original
/// text by path, and nothing in `identities.me` tells a TOML editor which
/// element `me` is. So a write resolves the address once, here, where the whole
/// document is in hand, and hands the backends the canonical `identities.0`.
/// The alternative — teaching six backends to match on content — would give
/// each its own chance to disagree with the read walk about what an address
/// means.
///
/// Resolution stops at the first segment the document does not have and copies
/// the rest verbatim, because `set` creates missing object parents and a node
/// that does not exist yet cannot be addressed by its content anyway. Whatever
/// is wrong with the tail is then the writer's error to report, unchanged.
///
/// Two prefixes are tracked because they answer different questions: the
/// *semantic* one (the caller's own segments) is what a [`KeyedList`]
/// registration is matched against, so a registration keeps meaning what it
/// meant on the read path, while the *canonical* one (resolved indices) is what
/// gets returned.
pub fn resolve_path(
    root: &Value,
    path: &str,
    addressing: Addressing<'_>,
) -> DocumentResult<String> {
    if path.is_empty() {
        return Ok(String::new());
    }

    let segments = parse_path(path)?;
    let mut current = root;
    let mut semantic: Vec<String> = Vec::new();
    let mut canonical: Vec<String> = Vec::with_capacity(segments.len());

    for (idx, segment) in segments.iter().enumerate() {
        let copy_rest = |canonical: &mut Vec<String>| {
            canonical.extend(segments[idx..].iter().cloned());
        };
        match current {
            Value::Object(object) => match object.get(segment.as_str()) {
                Some(next) => {
                    canonical.push(segment.clone());
                    semantic.push(segment.clone());
                    current = next;
                }
                None => {
                    copy_rest(&mut canonical);
                    break;
                }
            },
            Value::Array(array) => {
                let index = match array_index(segment)? {
                    Some(index) => index,
                    None => resolve_named_element(array, segment, &semantic, addressing)?,
                };
                let Some(next) = array.get(index) else {
                    copy_rest(&mut canonical);
                    break;
                };
                canonical.push(index.to_string());
                semantic.push(segment.clone());
                current = next;
            }
            _ => {
                copy_rest(&mut canonical);
                break;
            }
        }
    }

    Ok(join_path(&canonical))
}

/// Set a value at the given dot-path. `value` is inserted as-is at the leaf —
/// no coercion happens here; callers that accept CLI strings (e.g. the
/// `afdata` binary) construct the typed `Value` first, via
/// [`crate::document::coerce::value_from_type`] (an explicit `--value-type`)
/// or a bare `Value::String` (zero coercion), before calling this.
pub fn set_path(
    root: &mut Value,
    path: &str,
    value: &Value,
    addressing: Addressing<'_>,
) -> DocumentResult<()> {
    if path.is_empty() {
        return Err(DocumentError::EmptyPath);
    }

    let segments = parse_path(path)?;
    set_path_recursive(root, &segments, 0, &mut Vec::new(), addressing, value)
}

fn set_path_recursive(
    current: &mut Value,
    segments: &[String],
    idx: usize,
    accumulated_prefix: &mut Vec<String>,
    addressing: Addressing<'_>,
    value: &Value,
) -> DocumentResult<()> {
    if idx >= segments.len() {
        return Err(DocumentError::EmptyPath);
    }

    let current_seg = segments[idx].as_str();
    let is_last = idx == segments.len() - 1;

    match current {
        Value::Object(obj) => {
            // Path parsing makes dotted keys explicit via `\\.`.
            let key_to_use = current_seg.to_string();

            let segments_to_consume = 1;

            if is_last {
                // At leaf: insert the typed value directly.
                obj.insert(key_to_use, value.clone());
                Ok(())
            } else {
                // Not at leaf: ensure key exists and recurse
                let next_idx = idx + segments_to_consume;
                if next_idx >= segments.len() {
                    return Err(DocumentError::EmptyPath);
                }

                accumulated_prefix.push(key_to_use.clone());

                // Use entry API to avoid double borrow
                use std::collections::btree_map::Entry;
                match obj.entry(key_to_use) {
                    Entry::Occupied(mut ent) => set_path_recursive(
                        ent.get_mut(),
                        segments,
                        next_idx,
                        accumulated_prefix,
                        addressing,
                        value,
                    ),
                    Entry::Vacant(ent) => {
                        let mut new_obj = Value::Object(Default::default());
                        let result = set_path_recursive(
                            &mut new_obj,
                            segments,
                            next_idx,
                            accumulated_prefix,
                            addressing,
                            value,
                        );
                        if result.is_ok() {
                            ent.insert(new_obj);
                        }
                        result
                    }
                }
            }
        }
        Value::Array(arr) => {
            // Numeric index takes priority over keyed-list slug.
            if let Some(arr_idx) = array_index(current_seg)? {
                if arr_idx >= arr.len() {
                    return Err(DocumentError::IndexOutOfBounds {
                        path: join_path(accumulated_prefix),
                        index: arr_idx,
                        len: arr.len(),
                    });
                }
                if is_last {
                    arr[arr_idx] = value.clone();
                    Ok(())
                } else {
                    accumulated_prefix.push(current_seg.to_string());
                    set_path_recursive(
                        &mut arr[arr_idx],
                        segments,
                        idx + 1,
                        accumulated_prefix,
                        addressing,
                        value,
                    )
                }
            } else {
                let elem_idx =
                    resolve_named_element(arr, current_seg, accumulated_prefix, addressing)?;
                if is_last {
                    Err(DocumentError::UnsupportedOperation {
                        format: "keyed list".to_string(),
                        operation: "set".to_string(),
                        detail:
                            "a keyed-list slug resolves to an element; set a child field instead"
                                .to_string(),
                    })
                } else {
                    accumulated_prefix.push(current_seg.to_string());
                    set_path_recursive(
                        &mut arr[elem_idx],
                        segments,
                        idx + 1,
                        accumulated_prefix,
                        addressing,
                        value,
                    )
                }
            }
        }
        _ => Err(DocumentError::NotTraversable {
            path: join_path(accumulated_prefix),
            got: current.kind_name().to_string(),
        }),
    }
}

pub(crate) fn keyed_prefix_matches(
    registration: &KeyedList<'_>,
    semantic_prefix: &[String],
) -> bool {
    if registration.prefix.is_empty() {
        return semantic_prefix.is_empty();
    }
    crate::document::parse_path(registration.prefix)
        .ok()
        .is_some_and(|segments| segments == semantic_prefix)
}

/// Remove the key at the given dot-path from its parent object.
///
/// This is the free-fn "remove a key" verb (paired with keyed-element removal
/// via [`crate::document::remove_keyed`]).
pub fn unset_path(root: &mut Value, path: &str) -> DocumentResult<()> {
    if path.is_empty() {
        return Err(DocumentError::EmptyPath);
    }
    let segments = parse_path(path)?;
    unset_path_recursive(root, &segments, 0, &mut Vec::new())
}

fn unset_path_recursive(
    current: &mut Value,
    segments: &[String],
    idx: usize,
    accumulated_prefix: &mut Vec<String>,
) -> DocumentResult<()> {
    if idx >= segments.len() {
        return Err(DocumentError::EmptyPath);
    }
    let current_seg = segments[idx].as_str();
    let is_last = idx == segments.len() - 1;

    match current {
        Value::Object(obj) => {
            let key_to_use = current_seg.to_string();
            let segments_to_consume = 1;

            if is_last {
                if obj.remove(&key_to_use).is_none() {
                    return Err(DocumentError::PathNotFound { path: key_to_use });
                }
                Ok(())
            } else {
                let next_idx = idx + segments_to_consume;
                accumulated_prefix.push(key_to_use.clone());
                if let Some(next) = obj.get_mut(&key_to_use) {
                    unset_path_recursive(next, segments, next_idx, accumulated_prefix)
                } else {
                    Err(DocumentError::PathNotFound {
                        path: join_path(accumulated_prefix),
                    })
                }
            }
        }
        Value::Array(arr) => {
            if let Some(arr_idx) = array_index(current_seg)? {
                if arr_idx >= arr.len() {
                    return Err(DocumentError::IndexOutOfBounds {
                        path: join_path(accumulated_prefix),
                        index: arr_idx,
                        len: arr.len(),
                    });
                }
                if is_last {
                    arr.remove(arr_idx);
                    Ok(())
                } else {
                    accumulated_prefix.push(current_seg.to_string());
                    unset_path_recursive(&mut arr[arr_idx], segments, idx + 1, accumulated_prefix)
                }
            } else {
                Err(DocumentError::UnregisteredArray {
                    path: join_path(accumulated_prefix),
                })
            }
        }
        _ => Err(DocumentError::NotTraversable {
            path: join_path(accumulated_prefix),
            got: current.kind_name().to_string(),
        }),
    }
}

#[cfg(test)]
mod tests {
    #![allow(
        clippy::unwrap_used,
        clippy::panic,
        clippy::expect_used,
        clippy::bool_assert_comparison
    )]
    use super::*;

    fn make_test_object() -> Value {
        let mut root = Value::Object(Default::default());
        let mut imap = Value::Object(Default::default());
        imap.as_object_mut().unwrap().insert(
            "host".to_string(),
            Value::String("mail.example.com".to_string()),
        );
        imap.as_object_mut()
            .unwrap()
            .insert("port".to_string(), Value::Integer(993));

        root.as_object_mut()
            .unwrap()
            .insert("imap".to_string(), imap);

        root
    }

    #[test]
    fn test_get_path_simple() {
        let root = make_test_object();
        let result = get_path(&root, "imap.host", Addressing::INDEX_ONLY).unwrap();
        assert_eq!(result.as_str().unwrap(), "mail.example.com");
    }

    #[test]
    fn test_get_path_integer() {
        let root = make_test_object();
        let result = get_path(&root, "imap.port", Addressing::INDEX_ONLY).unwrap();
        assert_eq!(result.as_integer().unwrap(), 993);
    }

    #[test]
    fn test_set_path_new_key() {
        let mut root = make_test_object();
        set_path(
            &mut root,
            "imap.tls",
            &Value::Bool(true),
            Addressing::INDEX_ONLY,
        )
        .unwrap();

        let result = get_path(&root, "imap.tls", Addressing::INDEX_ONLY).unwrap();
        assert_eq!(result.as_bool().unwrap(), true);
    }

    #[test]
    fn test_set_path_overwrite() {
        let mut root = make_test_object();
        set_path(
            &mut root,
            "imap.port",
            &Value::Integer(587),
            Addressing::INDEX_ONLY,
        )
        .unwrap();

        let result = get_path(&root, "imap.port", Addressing::INDEX_ONLY).unwrap();
        assert_eq!(result.as_integer().unwrap(), 587);
    }

    #[test]
    fn test_set_path_array_value() {
        let mut root = Value::Object(Default::default());
        let value = Value::Array(vec![
            Value::String("dev".to_string()),
            Value::String("staging".to_string()),
        ]);
        set_path(&mut root, "tags", &value, Addressing::INDEX_ONLY).unwrap();

        let result = get_path(&root, "tags", Addressing::INDEX_ONLY).unwrap();
        let arr = result.as_array().unwrap();
        assert_eq!(arr.len(), 2);
    }

    fn make_steps_object() -> Value {
        // { "steps": [{"name": "a", "port": 1}, {"name": "b", "port": 2}] }
        let mut root = Value::Object(Default::default());
        let mut s0 = Value::Object(Default::default());
        s0.as_object_mut()
            .unwrap()
            .insert("name".to_string(), Value::String("a".to_string()));
        s0.as_object_mut()
            .unwrap()
            .insert("port".to_string(), Value::Integer(1));
        let mut s1 = Value::Object(Default::default());
        s1.as_object_mut()
            .unwrap()
            .insert("name".to_string(), Value::String("b".to_string()));
        s1.as_object_mut()
            .unwrap()
            .insert("port".to_string(), Value::Integer(2));
        root.as_object_mut()
            .unwrap()
            .insert("steps".to_string(), Value::Array(vec![s0, s1]));
        root
    }

    #[test]
    fn test_get_path_numeric_index() {
        let root = make_steps_object();
        let name = get_path(&root, "steps.0.name", Addressing::INDEX_ONLY).unwrap();
        assert_eq!(name.as_str().unwrap(), "a");
        let port = get_path(&root, "steps.1.port", Addressing::INDEX_ONLY).unwrap();
        assert_eq!(port.as_integer().unwrap(), 2);
    }

    #[test]
    fn test_set_path_numeric_index() {
        let mut root = make_steps_object();
        set_path(
            &mut root,
            "steps.0.port",
            &Value::Integer(99),
            Addressing::INDEX_ONLY,
        )
        .unwrap();
        let result = get_path(&root, "steps.0.port", Addressing::INDEX_ONLY).unwrap();
        assert_eq!(result.as_integer().unwrap(), 99);
        // other element unchanged
        let other = get_path(&root, "steps.1.port", Addressing::INDEX_ONLY).unwrap();
        assert_eq!(other.as_integer().unwrap(), 2);
    }

    #[test]
    fn test_get_path_index_out_of_bounds() {
        let root = make_steps_object();
        let err = get_path(&root, "steps.5.name", Addressing::INDEX_ONLY).unwrap_err();
        assert!(matches!(
            err,
            DocumentError::IndexOutOfBounds {
                index: 5,
                len: 2,
                ..
            }
        ));
    }

    #[test]
    fn test_remove_path_numeric_index() {
        let mut root = make_steps_object();
        unset_path(&mut root, "steps.0").unwrap();
        let arr = get_path(&root, "steps", Addressing::INDEX_ONLY).unwrap();
        let arr = arr.as_array().unwrap();
        assert_eq!(arr.len(), 1);
        assert_eq!(arr[0].get("name").unwrap().as_str().unwrap(), "b");
    }

    #[test]
    fn named_root_array_keeps_a_semantic_prefix_for_nested_keyed_lists() {
        let mut child = Value::Object(Default::default());
        child
            .as_object_mut()
            .unwrap()
            .insert("id".to_string(), Value::String("beta".to_string()));
        child
            .as_object_mut()
            .unwrap()
            .insert("value".to_string(), Value::Integer(1));

        let mut parent = Value::Object(Default::default());
        parent
            .as_object_mut()
            .unwrap()
            .insert("id".to_string(), Value::String("alpha".to_string()));
        parent
            .as_object_mut()
            .unwrap()
            .insert("children".to_string(), Value::Array(vec![child]));

        let mut root = Value::Array(vec![parent]);
        let keyed = [
            KeyedList {
                prefix: "",
                slug_field: "id",
            },
            KeyedList {
                prefix: "alpha.children",
                slug_field: "id",
            },
        ];
        let addressing = Addressing::keyed(&keyed);

        assert_eq!(
            get_path(&root, "alpha.children.beta.value", addressing).unwrap(),
            Value::Integer(1)
        );
        set_path(
            &mut root,
            "alpha.children.beta.value",
            &Value::Integer(2),
            addressing,
        )
        .unwrap();
        assert_eq!(
            get_path(&root, "alpha.children.beta.value", addressing).unwrap(),
            Value::Integer(2)
        );
    }

    #[test]
    fn oversized_decimal_array_segment_never_falls_through_to_a_slug() {
        let oversized = format!("{}0", usize::MAX);
        let mut item = Value::Object(Default::default());
        item.as_object_mut()
            .unwrap()
            .insert("id".to_string(), Value::String(oversized.clone()));
        let root = Value::Array(vec![item]);
        let keyed = [KeyedList {
            prefix: "",
            slug_field: "id",
        }];

        let error = get_path(&root, &oversized, Addressing::keyed(&keyed)).unwrap_err();
        assert!(matches!(error, DocumentError::PathSyntax { .. }));
    }

    #[test]
    fn dotted_key_and_nested_path_keep_distinct_keyed_registrations() {
        let item = |field: &str, slug: &str| {
            let mut value = Value::Object(Default::default());
            value
                .as_object_mut()
                .unwrap()
                .insert(field.to_string(), Value::String(slug.to_string()));
            value
        };

        let mut nested = Value::Object(Default::default());
        nested.as_object_mut().unwrap().insert(
            "b".to_string(),
            Value::Array(vec![item("nested_id", "nested")]),
        );

        let mut root = Value::Object(Default::default());
        root.as_object_mut().unwrap().insert(
            "a.b".to_string(),
            Value::Array(vec![item("dotted_id", "dotted")]),
        );
        root.as_object_mut()
            .unwrap()
            .insert("a".to_string(), nested);

        let keyed = [
            KeyedList {
                prefix: r"a\.b",
                slug_field: "dotted_id",
            },
            KeyedList {
                prefix: "a.b",
                slug_field: "nested_id",
            },
        ];
        let addressing = Addressing::keyed(&keyed);

        assert_eq!(
            get_path(&root, r"a\.b.dotted.dotted_id", addressing).unwrap(),
            Value::String("dotted".to_string())
        );
        assert_eq!(
            get_path(&root, "a.b.nested.nested_id", addressing).unwrap(),
            Value::String("nested".to_string())
        );
    }
}