Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Fn::ToJsonString

Focus mode
Fn::ToJsonString - AWS CloudFormation
Filter View

The Fn::ToJsonString intrinsic function converts an object or array to its corresponding JSON string.

Important

You must use the AWS::LanguageExtensions transform to use the Fn::ToJsonString intrinsic function.

Declaration

JSON

{ "Fn::ToJsonString": Object }
{ "Fn::ToJsonString": Array }

YAML

Fn::ToJsonString: Object
Fn::ToJsonString: Array

Parameters

Object

The object you want to convert to a JSON string.

Array

The array you want to convert to a JSON string.

Return value

The object or array converted to a JSON string.

Examples

Convert an object to a JSON string

This example snippet converts the object passed to the intrinsic function to a JSON string.

JSON

{ //... "Transform": "AWS::LanguageExtensions" //... "Fn::ToJsonString": { "key1": "value1", "key2": { "Ref": "ParameterName" } } //... }

YAML

Transform: 'AWS::LanguageExtensions' #... Fn::ToJsonString: key1: value1 key2: !Ref ParameterName #...

In both of these examples, if the Ref to ParameterName resolves to resolvedValue, the function resolves to the following JSON string:

"{\"key1\":\"value1\",\"key2\":\"resolvedValue\"}"

Convert an array to a JSON string

This example snippet converts the array passed to the intrinsic function to a JSON string.

JSON

{ //... "Transform": "AWS::LanguageExtensions" //... "Fn::ToJsonString": [{ "key1": "value1", "key2": { "Ref": "ParameterName" } }] //... }

YAML

Transform: 'AWS::LanguageExtensions' #... Fn::ToJsonString: - key1: value1 key2: !Ref ParameterName #...

In both of these examples, if the Ref to ParameterName resolves to resolvedValue, the function resolves to the following JSON String:

"[{\"key1\":\"value1\"},{\"key2\":\"resolvedValue\"}]"

Supported functions

You can use the following functions in the Fn::ToJsonString intrinsic function or array:

  • Fn::Base64

  • Fn::FindInMap

  • Fn::GetAtt

  • Fn::GetAZs

  • Fn::If

  • Fn::ImportValue

  • Fn::Join

  • Fn::Length

  • Fn::Select

  • Fn::Split

  • Fn::Sub

  • Fn::ToJsonString

  • Ref

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.