Updated on 2024-08-06 GMT+08:00

JSON Parameter Parsing Error

Symptoms

JSON parameters are not replaced or parsed as expected during the Ansible application deployment.

During the Ansible application deployment, the template module can be used to replace a text file. If the parameter values in the file are in JSON or JSON array format, the character u will be added in front of the keys and values after parsing. For example:
  • Input parameters: {"key":"jsonkey","value":"jsonvalue"}
  • Parameters after replacement: {u'value': u'jsonvalue', u'key': u'jsonkey'}

Solution

Enclose JSON parameters with single quotation marks. The template module will forcibly parse the parameters in character string mode to ensure correct replacement. The following is an example:

  • Input parameters: {"key":"jsonkey","value":"jsonvalue"}
  • Parameters after replacement: {"key":"jsonkey","value":"jsonvalue"}