Function encode

  • Encodes the value as a JSON string.

    An optional space string or number can be used as a indentation. If a string is provided, the string will be used as the indentation. If a number is provided, that number of spaces will be used as the indentation.

    If the space argument is left out, the JSON string will be generated with no extra whitespace.

    json.encode({hello: "world"}) === `{"hello":"world"}`
    

    Parameters

    • value: unknown
    • Optional space: string | number

    Returns string