Loosen JSON list parsing

This commit is contained in:
jeltz 2022-09-06 17:19:45 +02:00
parent 482bc9ecb6
commit 82ae6dbc33
Signed by: jeltz
GPG key ID: 800882B66C0C3326

View file

@ -38,9 +38,11 @@ module Addrs = struct
&> (str |> name)
end
let to_list_loose = function `List list -> list | _ -> []
let to_int_list json =
let open Yojson.Basic.Util in
json |> to_list |> List.map to_int
json |> to_list_loose |> List.map to_int
module PayloadRule = struct
module Tcp = struct
@ -74,9 +76,7 @@ module PayloadRule = struct
| _ -> assert false
end
let to_addr_list json =
let open Yojson.Basic.Util in
json |> to_list |> List.map Addrs.of_json
let to_addr_list json = json |> to_list_loose |> List.map Addrs.of_json
module Rule = struct
type t = { src : Addrs.t list; dest : Addrs.t list; payload : PayloadRule.t }
@ -98,5 +98,7 @@ let zones_of_json json =
let of_json json =
let open Yojson.Basic.Util in
let zones = json |> member "zones" |> zones_of_json in
let rules = json |> member "rules" |> to_list |> List.map Rule.of_json in
let rules =
json |> member "rules" |> to_list_loose |> List.map Rule.of_json
in
{ zones; rules }