My agentic slop goes here. Not intended for anyone else!
1open Ezjsonm
2
3(* Combinations of find + get_* that are commonly used *)
4let find_string json path =
5 find json path |> get_string
6
7let find_int json path =
8 find json path |> get_int
9
10let find_bool json path =
11 find json path |> get_bool
12
13let find_float json path =
14 find json path |> get_float
15
16(* Optional versions using Ezjsonm's find_opt *)
17let find_string_opt json path =
18 Option.map get_string (find_opt json path)
19
20let find_int_opt json path =
21 Option.map get_int (find_opt json path)
22
23let find_bool_opt json path =
24 Option.map get_bool (find_opt json path)
25
26let find_float_opt json path =
27 Option.map get_float (find_opt json path)
28
29let assoc_string key fields =
30 List.assoc key fields |> get_string
31
32let assoc_int key fields =
33 List.assoc key fields |> get_int
34
35let assoc_bool key fields =
36 List.assoc key fields |> get_bool
37
38let assoc_float key fields =
39 List.assoc key fields |> get_float
40
41let assoc_string_opt key fields =
42 Option.map get_string (List.assoc_opt key fields)
43
44let assoc_int_opt key fields =
45 Option.map get_int (List.assoc_opt key fields)
46
47let assoc_bool_opt key fields =
48 Option.map get_bool (List.assoc_opt key fields)
49
50let assoc_float_opt key fields =
51 Option.map get_float (List.assoc_opt key fields)
52
53(* Ezjsonm.get_dict extracts fields, but we keep get_fields as an alias for clarity *)
54let get_fields = get_dict
55
56(* Single field access - simpler than using find with a single-element path *)
57let get_field json key =
58 List.assoc key (get_dict json)
59
60let get_field_opt json key =
61 List.assoc_opt key (try get_dict json with _ -> [])
62
63let get_field_string json key =
64 get_field json key |> get_string
65
66let get_field_int json key =
67 get_field json key |> get_int
68
69let get_field_bool json key =
70 get_field json key |> get_bool
71
72let get_field_float json key =
73 get_field json key |> get_float
74
75let get_field_string_opt json key =
76 Option.map get_string (get_field_opt json key)
77
78let get_field_int_opt json key =
79 Option.map get_int (get_field_opt json key)
80
81let get_field_bool_opt json key =
82 Option.map get_bool (get_field_opt json key)
83
84let get_field_float_opt json key =
85 Option.map get_float (get_field_opt json key)