Skip to content

Replace jsonify() use(s), accounting for json.dumps() differences #1274

Description

@moreati

Prior to removal/restorationansible.parsing.utils.jsonify.jsonify() changed very little. Differences to json.dumps()

  1. jsonify(None) -> '{}' vs dumps(None) -> 'null'
  2. jsonify(..., format: bool) vs dumps(..., indent: int|None, ...)
  3. jsonify() always applies sort_keys=True.
  4. jsonify() prefers ensure_ascii=False, falling back to ensure_ascii=True on UnicodeDecodeError. I'm unsure what would trigger that exception only in the former case.

Refs

  1. https://github.com/ansible/ansible/blame/a0495fc31497798a7a833ba7406a9729e1528dd8/lib/ansible/parsing/utils/jsonify.py
  2. https://docs.python.org/3/library/json.html#basic-usage

Originally posted by @moreati in #1258

Edit 2025-06-17: Corrected return types when None is passed. Both return str on Python 2.x, and on Python 3.x.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions