JSONUtils

public struct JSONUtils

A utility structure providing helper methods for JSON serialization and manipulation.

JSONUtils offers static methods for common JSON operations, including converting objects to JSON strings with configurable formatting options.

  • Converts an object to JSON string representation.

    This method safely serializes any valid JSON object into its string representation, with optional pretty-printing for readability.

    Implementation Notes

    • Validates JSON object before serialization
    • Handles serialization errors gracefully
    • Uses UTF-8 encoding for string conversion

    Usage Example

    let data = ["action": "login", "score": 0.9]
    let jsonString = ReCaptchaEnterpriseUtils.jsonStringify(value: data as Any)
    

    Declaration

    Swift

    public static func jsonStringify(
        value: Any,
        prettyPrinted: Bool = false
    ) -> String

    Parameters

    value

    The object to convert to JSON

    prettyPrinted

    Whether to format JSON with indentation

    Return Value

    JSON string, or empty string if conversion fails