ansible.builtin.to_nice_json (v2.16.0) — filter

Convert variable to 'nicely formatted' JSON string

| "added in version" historical of ansible.builtin"

Authors: core team

Install Ansible via pip

Install with pip install ansible-core==2.16.0

Description

Converts an Ansible variable into a 'nicely formatted' JSON string representation

This filter functions as a wrapper to the Python C(json.dumps) function.

Ansible automatically converts JSON strings into variable structures so this plugin is used to forcibly retain a JSON string.

Inputs

    
_input:
    description: A variable or expression that returns a data structure.
    required: true
    type: raw

skipkeys:
    default: false
    description: If V(True), keys that are not basic Python types will be skipped.
    type: bool

allow_nan:
    default: true
    description: When V(False), strict adherence to float value limits of the JSON specification,
      so C(nan), C(inf) and C(-inf) values will produce errors. When V(True), JavaScript
      equivalents will be used (C(NaN), C(Infinity), C(-Infinity)).
    type: bool

ensure_ascii:
    default: true
    description: Escapes all non ASCII characters.
    type: bool

vault_to_text:
    default: true
    description: Toggle to either unvault a vault or create the JSON version of a vaulted
      object.
    type: bool
    version_added: '2.9'
    version_added_collection: ansible.builtin

check_circular:
    default: true
    description: Controls the usage of the internal circular reference detection, if off
      can result in overflow errors.
    type: bool

preprocess_unsafe:
    default: true
    description: Toggle to represent unsafe values directly in JSON or create a unsafe
      object in JSON.
    type: bool
    version_added: '2.9'
    version_added_collection: ansible.builtin

Outputs

_value:
  description: The 'nicely formatted' JSON serialized string representing the variable
    structure inputted.
  type: string