Skip to content

JSONata with $eval trying to convert JSON string to JSON object

0

I'm getting an error when I use the $eval function in JSONata

JSONata error

I'm attempting to coerse a JSON string into a JSON object. Base on this issue closed in 2018, I believe JSONata has this capability. Is this being blocked by AWS?

If eval is NOT available can someone suggest, using JSONata, how to coerce a string into an object?

asked a year ago2.7K views
2 Answers
2

Step Functions does not support JSONata's $eval. For that reason, we added $parse, as a special Step Functions function to parse a JSON String into a JSON Object. You can see this in the doc.

AWS
EXPERT
answered a year ago
EXPERT
reviewed 10 months ago
EXPERT
reviewed a year ago
  • Missed that. Thank you!

1

It appears that you're encountering an issue while trying to use the $eval function in JSONata within AWS Step Functions. Unfortunately, AWS Step Functions does not support all JSONata functions, and $eval is likely one of the unsupported functions.

While $eval is not available, there are alternative approaches you can use in AWS Step Functions to transform a JSON string into a JSON object using JSONata:

  1. If you know the structure of your JSON string, you can use JSONata's parsing capabilities directly. For example, if your JSON string is stored in a variable called $jsonString, you could try:

    $parse($jsonString)

  2. If the JSON string is already valid JSON, you might not need to use any special function. JSONata in Step Functions should automatically parse it when you reference it.

  3. You can use the built-in JSON parsing capabilities of Step Functions. Instead of using JSONata for this specific task, you could use a Pass state with Parameters to parse the JSON string.

  4. If none of these methods work for your specific use case, you might need to consider using a Lambda function to perform the JSON string to object conversion.

Remember, when using JSONata in AWS Step Functions, you need to opt-in by setting the QueryLanguage field to JSONata in your workflow definition. This replaces the traditional InputPath, Parameters, ResultSelector, ResultPath, and OutputPath fields with Arguments and Output fields that use JSONata expressions.

If you continue to face issues, it might be helpful to share more details about your specific JSON string and the exact transformation you're trying to achieve. This would allow for more tailored suggestions within the constraints of AWS Step Functions and its implementation of JSONata.

Sources
Transforming data with JSONata in Step Functions - AWS Step Functions
Simplifying developer experience with variables and JSONata in AWS Step Functions | AWS Compute Blog
AWS Step Functions simplifies developer experience with Variables and JSONata transformations - AWS

answered a year ago
EXPERT
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.