unittest2doc.formatter.json_formatter

Functions:

data2json(d[, prefix])

custom dump for json: add prefix for each line

pformat_json(data[, comments, indent, ...])

Pretty format JSON data with support for a comment system

unittest2doc.formatter.json_formatter.data2json(d: Any, prefix: str = '\t') str

custom dump for json: add prefix for each line

Parameters:
  • d (Any) – dict to dump

  • prefix (str) – prefix to be added into each line

Returns:

the json str of input

Return type:

str

unittest2doc.formatter.json_formatter.pformat_json(data, comments: str | dict | None = None, indent: int = 2, level: int = 0, comment_prefix: str = '# ', compact: int | None = None, debug: bool = False)

Pretty format JSON data with support for a comment system

This function formats nested Python data structures (dicts, lists, etc.) into a readable string representation with support for various types of comments.

Parameters:
  • data – Data to format (dict, list, or simple value)

  • comments (str | dict | None) – Comment configuration, can be a dict or string - Dict type supports advanced commenting features (see below) - String type serves as a title comment for the top-level object

  • indent (int) – Number of spaces for indentation

  • level (int) – Current recursion level (used for indentation)

  • comment_prefix (str) – Comment prefix character(s), defaults to “# “

Dict comment special keys:

__dtitle__: String, shown as dict title after opening brace __lcompact__: Integer, maximum line length for compact mode __lsub__: Any value, comments to apply to all child elements

List comment special keys:

__ltitle__: String, shown as list title after opening bracket __lprefix__: List, prefix comment lines to add at the beginning __lsuffix__: List, suffix comment lines to add at the end __lcompact__: Integer, maximum line length for compact mode __llist__: Any value, comments to apply to all list-type child elements __ldict__: Any value, comments to apply to all dict-type child elements __lsub__: Any value, comments to apply to all child elements Integer keys: Comments to apply to specific index elements

Returns:

Formatted data string