···2233import argv
44import gleam/dict.{type Dict}
55+import gleam/dynamic
56import gleam/dynamic/decode
67import gleam/int
78import gleam/io
···199200 Error("Value does not match format: " <> format_name)
200201 }
201202 }
203203+}
204204+205205+/// Convert a Dynamic value to Json
206206+///
207207+/// This is useful when parsing JSON strings with `json.parse(str, decode.dynamic)`
208208+/// and then needing to convert to Json for validation.
209209+///
210210+/// ## Example
211211+/// ```gleam
212212+/// use dyn <- result.try(json.parse(json_str, decode.dynamic))
213213+/// use json_val <- result.try(honk.dynamic_to_json(dyn))
214214+/// honk.validate([json_val])
215215+/// ```
216216+pub fn dynamic_to_json(dyn: dynamic.Dynamic) -> Result(Json, ValidationError) {
217217+ json_helpers.dynamic_to_json(dyn)
218218+}
219219+220220+/// Parse a JSON string and convert to Json for validation
221221+///
222222+/// This is a convenience function that combines `json.parse()` and `dynamic_to_json()`.
223223+/// It's useful when you have JSON stored as strings (e.g., in a database) and want
224224+/// to validate it with honk.
225225+///
226226+/// ## Example
227227+/// ```gleam
228228+/// use json_val <- result.try(honk.parse_json_string(stored_json))
229229+/// honk.validate([json_val])
230230+/// ```
231231+pub fn parse_json_string(json_str: String) -> Result(Json, ValidationError) {
232232+ use dyn <- result.try(
233233+ json.parse(json_str, decode.dynamic)
234234+ |> result.map_error(fn(_) {
235235+ errors.invalid_schema("Failed to parse JSON string")
236236+ }),
237237+ )
238238+ dynamic_to_json(dyn)
239239+}
240240+241241+/// Parse multiple JSON strings and convert to Json for validation
242242+///
243243+/// This is a convenience function for batch parsing JSON strings.
244244+///
245245+/// ## Example
246246+/// ```gleam
247247+/// use json_vals <- result.try(honk.parse_json_strings(stored_jsons))
248248+/// honk.validate(json_vals)
249249+/// ```
250250+pub fn parse_json_strings(
251251+ json_strs: List(String),
252252+) -> Result(List(Json), ValidationError) {
253253+ json_strs
254254+ |> list.try_map(parse_json_string)
255255+ |> result.map_error(fn(_) {
256256+ errors.invalid_schema("Failed to parse JSON strings")
257257+ })
202258}
203259204260/// CLI entry point for the honk lexicon validator