In AWS Step Function State Machines, how do you enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS

Viewed 354

When making a call to a State Machine with float('nan') in the payload, the result hints to enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS because of the Non-standard token 'NaN' .

import boto3
import json
client = boto3.client('stepfunctions', endpoint_url=endpoint_url)
client.start_sync_execution(stateMachineArn='state_machine_arn',
                            name='new-execution',
                            input=json.dumps({'foo': float('nan')})

(truncating)

InvalidExecutionInput                     Traceback (most recent call last)
...
~/opt/miniconda3/envs/pandars38/lib/python3.8/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
    674             error_code = parsed_response.get("Error", {}).get("Code")
    675             error_class = self.exceptions.from_code(error_code)
--> 676             raise error_class(parsed_response, operation_name)
    677         else:
    678             return parsed_response

InvalidExecutionInput: An error occurred (InvalidExecutionInput) when calling the StartSyncExecution operation: Invalid State Machine Execution Input: 'Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow'

(wrapping)

InvalidExecutionInput: 
    An error occurred (InvalidExecutionInput) when calling the StartSyncExecution operation: 
    Invalid State Machine Execution Input: 
    'Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow'

The same exception happens with the numpy np.nan as well.

1 Answers

NaN is not a valid JSON value according to the official JSON specifications. https://www.json.org/json-en.html

Step Functions only supports standard tokens which conform to the official JSON specifications.

I suggest to encode your NaN to null.

Related