pkgs:
let
inherit (builtins) match toJSON typeOf elem;
inherit (pkgs.lib) mapAttrsToList concatStringsSep concatMapStringsSep;
isZigId = id: match "[[:alpha:]_][[:alpha:][:digit:]_]*" id != null;
zonField = id: if isZigId id then ".${id}" else ".@\"${id}\"";
zonElem = id: val: "${zonField id} = ${toZON val}";
zonAttrs = a: ".{ ${a |> mapAttrsToList zonElem |> concatStringsSep ", "} }";
zonVal = toJSON;
# to tuple
zonList = list: ".{ ${concatMapStringsSep ", " toZON list} }";
toZON = a: let type = typeOf a; in
if elem type ["int" "float" "string" "path"]
then zonVal a
else if type == "list"
then zonList a
else if type == "set"
then zonAttrs a
else abort "Not implemented type: ${type}";
in zonAttrs