Skip to content
v2.274.0

JsonPath Class ​

Extract a field from the State Machine data or context that gets passed around between states.

Example ​

ts
new tasks.SageMakerCreateModel(this, 'Sagemaker', {
  modelName: 'MyModel',
  primaryContainer: new tasks.ContainerDefinition({
    image: tasks.DockerImage.fromJsonExpression(sfn.JsonPath.stringAt('$.Model.imageName')),
    mode: tasks.Mode.SINGLE_MODEL,
    modelS3Location: tasks.S3Location.fromJsonExpression('$.TrainingJob.ModelArtifacts.S3ModelArtifacts'),
  }),
});

Properties ​

DISCARDstringdiscardstrDISCARDStringDISCARDstringDISCARD*stringrequiredstatic#
Special string value to discard state input, output or result.
entireContextstringentire_contextstrentireContextStringEntireContextstringEntireContext*stringrequiredstatic#
Use the entire context data structure.

Will be an object at invocation time, but is represented in the CDK application as a string.

entirePayloadstringentire_payloadstrentirePayloadStringEntirePayloadstringEntirePayload*stringrequiredstatic#
Use the entire data structure.

Will be an object at invocation time, but is represented in the CDK application as a string.

executionIdstringexecution_idstrexecutionIdStringExecutionIdstringExecutionId*stringrequiredstatic#
Return the Execution Id field from the context object.
executionInputstringexecution_inputstrexecutionInputStringExecutionInputstringExecutionInput*stringrequiredstatic#
Return the Execution Input field from the context object.
  • Will be an object at invocation time, but is represented in the CDK application as a string.
executionNamestringexecution_namestrexecutionNameStringExecutionNamestringExecutionName*stringrequiredstatic#
Return the Execution Name field from the context object.
executionRoleArnstringexecution_role_arnstrexecutionRoleArnStringExecutionRoleArnstringExecutionRoleArn*stringrequiredstatic#
Return the Execution RoleArn field from the context object.
executionStartTimestringexecution_start_timestrexecutionStartTimeStringExecutionStartTimestringExecutionStartTime*stringrequiredstatic#
Return the Execution StartTime field from the context object.
stateEnteredTimestringstate_entered_timestrstateEnteredTimeStringStateEnteredTimestringStateEnteredTime*stringrequiredstatic#
Return the State EnteredTime field from the context object.
stateMachineIdstringstate_machine_idstrstateMachineIdStringStateMachineIdstringStateMachineId*stringrequiredstatic#
Return the StateMachine Id field from the context object.
stateMachineNamestringstate_machine_namestrstateMachineNameStringStateMachineNamestringStateMachineName*stringrequiredstatic#
Return the StateMachine Name field from the context object.
stateNamestringstate_namestrstateNameStringStateNamestringStateName*stringrequiredstatic#
Return the State Name field from the context object.
stateRetryCountstringstate_retry_countstrstateRetryCountStringStateRetryCountstringStateRetryCount*stringrequiredstatic#
Return the State RetryCount field from the context object.
taskTokenstringtask_tokenstrtaskTokenStringTaskTokenstringTaskToken*stringrequiredstatic#
Return the Task Token field from the context object.

External actions will need this token to report step completion back to StepFunctions using the SendTaskSuccess or SendTaskFailure calls.

Methods ​

array(...values: string[]): string@staticmethod def array(values: str) -> strpublic static String array(String values)public static string Array(string values)func Array(Values *string) *stringstatic#
Make an intrinsic States.Array expression.
notes

Combine any number of string literals or JsonPath expressions into an array.

Use this function if the value of an array element directly has to come from a JSON Path expression (either the State object or the Context object).

If the array contains object literals whose values come from a JSON path expression, you do not need to use this function.

arrayContains(array: any, value: any): string@staticmethod def array_contains(array: Any, value: Any) -> strpublic static String arrayContains(Object array, Object value)public static string ArrayContains(object array, object value)func ArrayContains(Array interface{}, Value interface{}) *stringstatic#
Make an intrinsic States.ArrayContains expression.

Use this function to determine if a specific value is present in an array. For example, you can use this function to detect if there was an error in a Map state iteration.

arrayGetItem(array: any, index: number): string@staticmethod def array_get_item(array: Any, index: int | float) -> strpublic static String arrayGetItem(Object array, Number index)public static string ArrayGetItem(object array, double index)func ArrayGetItem(Array interface{}, Index *float64) *stringstatic#
Make an intrinsic States.ArrayGetItem expression.

Use this function to get a specified index's value in an array.

arrayLength(array: any): string@staticmethod def array_length(array: Any) -> strpublic static String arrayLength(Object array)public static string ArrayLength(object array)func ArrayLength(Array interface{}) *stringstatic#
Make an intrinsic States.ArrayLength expression.

Use this function to get the length of an array.

arrayPartition(array: any, chunkSize: number): string@staticmethod def array_partition(array: Any, chunk_size: int | float) -> strpublic static String arrayPartition(Object array, Number chunkSize)public static string ArrayPartition(object array, double chunkSize)func ArrayPartition(Array interface{}, ChunkSize *float64) *stringstatic#
Make an intrinsic States.ArrayPartition expression.

Use this function to partition a large array. You can also use this intrinsic to slice the data and then send the payload in smaller chunks.

arrayRange(start: number, end: number, step: number): string@staticmethod def array_range(start: int | float, end: int | float, step: int | float) -> strpublic static String arrayRange(Number start, Number end, Number step)public static string ArrayRange(double start, double end, double step)func ArrayRange(Start *float64, End *float64, Step *float64) *stringstatic#
Make an intrinsic States.ArrayRange expression.

Use this function to create a new array containing a specific range of elements. The new array can contain up to 1000 elements.

arrayUnique(array: any): string@staticmethod def array_unique(array: Any) -> strpublic static String arrayUnique(Object array)public static string ArrayUnique(object array)func ArrayUnique(Array interface{}) *stringstatic#
Make an intrinsic States.ArrayUnique expression.

Use this function to get the length of an array. Use this function to remove duplicate values from an array and returns an array containing only unique elements. This function takes an array, which can be unsorted, as its sole argument.

base64Decode(base64: string): string@staticmethod def base64_decode(base64: str) -> strpublic static String base64Decode(String base64)public static string Base64Decode(string base64)func Base64Decode(Base64 *string) *stringstatic#
Make an intrinsic States.Base64Decode expression.

Use this function to decode data based on MIME Base64 decoding scheme. You can use this function to pass data to other AWS services without using a Lambda function.

base64Encode(input: string): string@staticmethod def base64_encode(input: str) -> strpublic static String base64Encode(String input)public static string Base64Encode(string input)func Base64Encode(Input *string) *stringstatic#
Make an intrinsic States.Base64Encode expression.

Use this function to encode data based on MIME Base64 encoding scheme. You can use this function to pass data to other AWS services without using an AWS Lambda function.

format(formatString: string, ...values: string[]): string@staticmethod def format(format_string: str, values: str) -> strpublic static String format(String formatString, String values)public static string Format(string formatString, string values)func Format(FormatString *string, Values *string) *stringstatic#
Make an intrinsic States.Format expression.

This can be used to embed JSON Path variables inside a format string.

For example:

ts
sfn.JsonPath.format('Hello, my name is {}.', sfn.JsonPath.stringAt('$.name'))
hash(data: any, algorithm: string): string@staticmethod def hash(data: Any, algorithm: str) -> strpublic static String hash(Object data, String algorithm)public static string Hash(object data, string algorithm)func Hash(Data interface{}, Algorithm *string) *stringstatic#
Make an intrinsic States.Hash expression.

Use this function to calculate the hash value of a given input. You can use this function to pass data to other AWS services without using a Lambda function.

isEncodedJsonPath(value: string): boolean@staticmethod def is_encoded_json_path(value: str) -> boolpublic static Boolean isEncodedJsonPath(String value)public static bool IsEncodedJsonPath(string value)func IsEncodedJsonPath(Value *string) *boolstatic#
Determines if the indicated string is an encoded JSON path.
1 parameter

Parameters

  • valuevaluevaluevalueValue — string to be evaluated.
jsonMerge(value1: any, value2: any): string@staticmethod def json_merge(value1: Any, value2: Any) -> strpublic static String jsonMerge(Object value1, Object value2)public static string JsonMerge(object value1, object value2)func JsonMerge(Value1 interface{}, Value2 interface{}) *stringstatic#
Make an intrinsic States.JsonMerge expression.

Use this function to merge two JSON objects into a single object.

jsonToString(value: any): string@staticmethod def json_to_string(value: Any) -> strpublic static String jsonToString(Object value)public static string JsonToString(object value)func JsonToString(Value interface{}) *stringstatic#
Make an intrinsic States.JsonToString expression.

During the execution of the Step Functions state machine, encode the given object into a JSON string.

For example:

ts
sfn.JsonPath.jsonToString(sfn.JsonPath.objectAt('$.someObject'))
listAt(path: string): string[]@staticmethod def list_at(path: str) -> typing.List[str]public static List<String> listAt(String path)public static string[] ListAt(string path)func ListAt(Path *string) *[]*stringstatic#
Instead of using a literal string list, get the value from a JSON path.
mathAdd(num1: number, num2: number): string@staticmethod def math_add(num1: int | float, num2: int | float) -> strpublic static String mathAdd(Number num1, Number num2)public static string MathAdd(double num1, double num2)func MathAdd(Num1 *float64, Num2 *float64) *stringstatic#
Make an intrinsic States.MathAdd expression.

Use this function to return the sum of two numbers. For example, you can use this function to increment values inside a loop without invoking a Lambda function.

mathRandom(start: number, end: number): string@staticmethod def math_random(start: int | float, end: int | float) -> strpublic static String mathRandom(Number start, Number end)public static string MathRandom(double start, double end)func MathRandom(Start *float64, End *float64) *stringstatic#
Make an intrinsic States.MathRandom expression.

Use this function to return a random number between the specified start and end number. For example, you can use this function to distribute a specific task between two or more resources.

numberAt(path: string): number@staticmethod def number_at(path: str) -> int | floatpublic static Number numberAt(String path)public static double NumberAt(string path)func NumberAt(Path *string) *float64static#
Instead of using a literal number, get the value from a JSON path.
objectAt(path: string): IResolvable@staticmethod def object_at(path: str) -> IResolvablepublic static IResolvable objectAt(String path)public static IResolvable ObjectAt(string path)func ObjectAt(Path *string) IResolvablestatic#
Reference a complete (complex) object in a JSON path location.
stringAt(path: string): string@staticmethod def string_at(path: str) -> strpublic static String stringAt(String path)public static string StringAt(string path)func StringAt(Path *string) *stringstatic#
Instead of using a literal string, get the value from a JSON path.
stringSplit(inputString: string, splitter: string): string@staticmethod def string_split(input_string: str, splitter: str) -> strpublic static String stringSplit(String inputString, String splitter)public static string StringSplit(string inputString, string splitter)func StringSplit(InputString *string, Splitter *string) *stringstatic#
Make an intrinsic States.StringSplit expression.

Use this function to split a string into an array of values. This function takes two arguments.The first argument is a string and the second argument is the delimiting character that the function will use to divide the string.

stringToJson(jsonString: string): IResolvable@staticmethod def string_to_json(json_string: str) -> IResolvablepublic static IResolvable stringToJson(String jsonString)public static IResolvable StringToJson(string jsonString)func StringToJson(JsonString *string) IResolvablestatic#
Make an intrinsic States.StringToJson expression.

During the execution of the Step Functions state machine, parse the given argument as JSON into its object form.

For example:

ts
sfn.JsonPath.stringToJson(sfn.JsonPath.stringAt('$.someJsonBody'))
uuid(): string@staticmethod def uuid() -> strpublic static String uuid()public static string Uuid()func Uuid() *stringstatic#
Make an intrinsic States.UUID expression.
notes

Use this function to return a version 4 universally unique identifier (v4 UUID) generated using random numbers. For example, you can use this function to call other AWS services or resources that need a UUID parameter or insert items in a DynamoDB table.