1. Docs
  2. Pulumi ESC
  3. Environment Definition Reference
  4. Built-in Functions
  5. fn::toJSON

fn::toJSON

    The fn::toJSON built-in function encodes a value as its JSON representation. This can be used to encode values for use in positions that only accept strings. If any input to fn::toJSON is a secret, the encoded values is also a secret.

    Declaration

    fn::toJSON: value-to-encode
    

    Parameters

    PropertyTypeDescription
    value-to-encodeanyThe value to encode as JSON.

    Returns

    The decoded value.

    Example

    Definition

    values:
      json-object:
        fn::toJSON:
          hello: world
    

    Evaluated result

    {
      "json-object": "{\"hello\": \"world\"}"
    }
    
      PulumiUP May 6, 2025. Register Now.