@@ -69,84 +69,99 @@ exception Undefined of string * t
6969 of bounds. *)
7070
7171val keys : t -> string list
72- (* * Returns all the key names in the given JSON object *)
72+ (* * Returns all the key names in the given JSON object.
73+ @raise Type_error if argument is not a JSON object. *)
7374
7475val values : t -> t list
75- (* * Return all the value in the given JSON object *)
76+ (* * Return all the value in the given JSON object.
77+ @raise Type_error if argument is not a JSON object. *)
7678
7779val combine : t -> t -> t
78- (* * Combine two JSON Objects together *)
80+ (* * Combine two JSON objects together.
81+ @raise Invalid_argument if either argument is not a JSON object. *)
7982
8083val member : string -> t -> t
8184 (* * [member k obj] returns the value associated with the key [k] in the JSON
82- object [obj], or [`Null] if [k] is not present in [obj]. *)
85+ object [obj], or [`Null] if [k] is not present in [obj].
86+ @raise Type_error if [obj] is not a JSON object. *)
8387
8488val index : int -> t -> t
8589 (* * [index i arr] returns the value at index [i] in the JSON array [arr].
8690 Negative indices count from the end of the list (so -1 is the last
87- element). *)
91+ element).
92+ @raise Type_error if [arr] is not a JSON array.
93+ @raise Undefined if index is out of bounds. *)
8894
8995val map : (t -> t ) -> t -> t
9096 (* * [map f arr] calls the function [f] on each element of the JSON array
91- [arr], and returns a JSON array containing the results. *)
97+ [arr], and returns a JSON array containing the results.
98+ @raise Type_error if [arr] is not an JSON array. *)
9299
93100val to_assoc : t -> (string * t ) list
94- (* * Extract the items of a JSON object or raise [Type_error]. *)
101+ (* * Extract the items of a JSON object.
102+ @raise Type_error if argument is not a JSON object. *)
95103
96104val to_option : (t -> 'a ) -> t -> 'a option
97105 (* * Return [None] if the JSON value is null or map the JSON value
98106 to [Some] value using the provided function. *)
99107
100108val to_bool : t -> bool
101- (* * Extract a boolean value or raise [Type_error]. *)
109+ (* * Extract a boolean value.
110+ @raise Type_error if argument is not a JSON boolean. *)
102111
103112val to_bool_option : t -> bool option
104113 (* * Extract [Some] boolean value,
105- return [None] if the value is null,
106- or raise [ Type_error] otherwise . *)
114+ return [None] if the value is null.
115+ @ raise Type_error if argument is neither . *)
107116
108117val to_number : t -> float
109- (* * Extract a number or raise [Type_error]. *)
118+ (* * Extract a number.
119+ @raise Type_error if argument is not a JSON number. *)
110120
111121val to_number_option : t -> float option
112122 (* * Extract [Some] number,
113- return [None] if the value is null,
114- or raise [ Type_error] otherwise . *)
123+ return [None] if the value is null.
124+ @ raise Type_error if argument is neither . *)
115125
116126val to_float : t -> float
117- (* * Extract a float value or raise [Type_error].
118- [to_number] is generally preferred as it also works with int literals. *)
127+ (* * Extract a float value.
128+ [to_number] is generally preferred as it also works with int literals.
129+ @raise Type_error if argument is not a JSON float. *)
119130
120131val to_float_option : t -> float option
121132 (* * Extract [Some] float value,
122- return [None] if the value is null,
123- or raise [Type_error] otherwise.
133+ return [None] if the value is null.
124134 [to_number_option] is generally preferred as it also works
125- with int literals. *)
135+ with int literals.
136+ @raise Type_error if argument is neither. *)
126137
127138val to_int : t -> int
128- (* * Extract an int from a JSON int or raise [Type_error]. *)
139+ (* * Extract an int from a JSON int.
140+ @raise Type_error if argument is not a JSON int. *)
129141
130142val to_int_option : t -> int option
131143 (* * Extract [Some] int from a JSON int,
132- return [None] if the value is null,
133- or raise [ Type_error] otherwise . *)
144+ return [None] if the value is null.
145+ @ raise Type_error if argument is neither . *)
134146
135147val to_list : t -> t list
136- (* * Extract a list from JSON array or raise [Type_error]. *)
148+ (* * Extract a list from JSON array.
149+ @raise Type_error if argument is not a JSON array. *)
137150
138151val to_string : t -> string
139- (* * Extract a string from a JSON string or raise [Type_error]. *)
152+ (* * Extract a string from a JSON string.
153+ @raise Type_error if argument is not a JSON string. *)
140154
141155val to_string_option : t -> string option
142156 (* * Extract [Some] string from a JSON string,
143- return [None] if the value is null,
144- or raise [ Type_error] otherwise . *)
157+ return [None] if the value is null.
158+ @ raise Type_error if argument is neither . *)
145159
146160val convert_each : (t -> 'a ) -> t -> 'a list
147161 (* * The conversion functions above cannot be used with [map], because they do
148162 not return JSON values. This convenience function [convert_each to_f arr]
149- is equivalent to [List.map to_f (to_list arr)]. *)
163+ is equivalent to [List.map to_f (to_list arr)].
164+ @raise Type_error if [arr] is not a JSON array. *)
150165
151166
152167(* * {3 Exception-free filters} *)
0 commit comments