aws / aws/aws-cdk

(stepfunctions): support return null for missing leaf in JSONPath

Open
#22,391 1 comment 7 reactions 1 assignee Claimed by @kaizencc View on GitHub
@aws-cdk/aws-stepfunctions feature-request p3 service-api
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### Describe the feature

Currently when using `JSONPath.stringAt` an error will be thrown if the key does not exist, this makes it difficult when working with objects with optional keys.

This would allow the enabling of returning null where a missing leaf occurs in the path.

### Use Case

Our use case for this primarily is to help with unmarshalling dynamoDB data from an optimised integration in another step without invoking a lambda but its use should be far more generic as explained below.

https://jsonpath.herokuapp.com/

For instance if you go here to view a potential data structure, if you were to remove the author and try to access this data using JSONPath.stringAt in a step function would throw an error (here it omits the data).

`$.store.book[*].['category','author']`

If you enable `Return null for missing leaf` this will return the value as null and retains the correct structure.

Error from Step Function run

```
JSONPath.stringAt('$$.Map.Item.Value.id.S')
```

> The JSONPath '$$.Map.Item.Value.id.S' specified for the field 'Item.id.$' could not be found in the input

With the above missing leaf as null enabled this would simply have returned `null`.

### Proposed Solution

Add in a config attribute for step functions that will allow you to change the behaviour of a missing leaf in JSONPath.

`JSONPathDefaultToNull: true`

This will then give far greater flexibility when working with optional keys in objects.

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.31.2

### Environment details (OS name and version, etc.)

MacOS 12.6

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.