# JsonPath

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

- Source: [`aws-stepfunctions/lib/fields.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-stepfunctions/lib/fields.ts#L13)
- Type last changed: v2.82.0 · 2 Jun 2023

## 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

- `DISCARD`: string (static) — Special string value to discard state input, output or result.

- `entireContext`: string (static) — Use the entire context data structure.

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

- `entirePayload`: string (static) — Use the entire data structure.

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

- `executionId`: string (static) — Return the Execution Id field from the context object.

- `executionInput`: string (static) — 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.

- `executionName`: string (static) — Return the Execution Name field from the context object.

- `executionRoleArn`: string (static) — Return the Execution RoleArn field from the context object.

- `executionStartTime`: string (static) — Return the Execution StartTime field from the context object.

- `stateEnteredTime`: string (static) — Return the State EnteredTime field from the context object.

- `stateMachineId`: string (static) — Return the StateMachine Id field from the context object.

- `stateMachineName`: string (static) — Return the StateMachine Name field from the context object.

- `stateName`: string (static) — Return the State Name field from the context object.

- `stateRetryCount`: string (static) — Return the State RetryCount field from the context object.

- `taskToken`: string (static) — 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` (static) — Make an intrinsic States.Array expression.

  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` (static) — 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` (static) — Make an intrinsic States.ArrayGetItem expression.

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

- `arrayLength(array: any): string` (static) — Make an intrinsic States.ArrayLength expression.

  Use this function to get the length of an array.

- `arrayPartition(array: any, chunkSize: number): string` (static) — 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` (static) — 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` (static) — 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` (static) — 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` (static) — 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` (static) — 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` (static) — 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` (static) — Determines if the indicated string is an encoded JSON path.

  **Parameters**

  - `value` — string to be evaluated.

- `jsonMerge(value1: any, value2: any): string` (static) — Make an intrinsic States.JsonMerge expression.

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

- `jsonToString(value: any): string` (static) — 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[]` (static) — Instead of using a literal string list, get the value from a JSON path.

- `mathAdd(num1: number, num2: number): string` (static) — 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` (static) — 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` (static) — Instead of using a literal number, get the value from a JSON path.

- `objectAt(path: string): IResolvable` (static) — Reference a complete (complex) object in a JSON path location.

- `stringAt(path: string): string` (static) — Instead of using a literal string, get the value from a JSON path.

- `stringSplit(inputString: string, splitter: string): string` (static) — 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` (static) — 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` (static) — Make an intrinsic States.UUID expression.

  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.
