import PureYAML public extension PureYAML.JSON { /// JSON-representability checks built on PureYAML's own validation framework. /// The parser already guarantees the input is well-formed YAML (and so covers /// JSON syntax); this layer reports the value-level reasons a tree cannot be /// emitted as JSON: a non-string mapping key, a non-finite number, or (for a /// deterministic single-meaning document) a duplicate key. /// /// JSON the format tolerates duplicate object names, but a tree that carries two /// pairs with the same key emits an ambiguous document, so the representability /// validator rejects duplicates for determinism. Drop ``unique`` from the rule /// set if you want the permissive reading. enum Validator { /// The full JSON-representability rule set: unique keys, string keys, finite /// numbers. Suitable to pass straight to `PureYAML.JSON.Convert`. public static var representability: PureYAML.Validation.Validator { PureYAML.Validation.Validator(rules: [ .mappingKeysAreUnique, .mappingKeysAreStrings, .numbersAreFinite, ]) } /// Every reason the value cannot be emitted as strict JSON, in document order. public static func issues(for value: PureYAML.Model.Value) -> [PureYAML.Validation.Issue] { representability.collect(value).issues } /// Whether the value can be emitted as strict JSON. public static func isRepresentable(_ value: PureYAML.Model.Value) -> Bool { issues(for: value).isEmpty } } }