added print_json

This commit is contained in:
Will McGugan 2021-08-28 15:04:06 +01:00
parent 69ea180f75
commit 6e76b2216f
11 changed files with 159 additions and 2 deletions

View file

@ -69,6 +69,24 @@ The :meth:`~rich.console.Console.log` methods offers the same capabilities as pr
To help with debugging, the log() method has a ``log_locals`` parameter. If you set this to ``True``, Rich will display a table of local variables where the method was called.
Printing JSON
-------------
The :meth:`~rich.console.Console.print_json` method will pretty print (format and style) a string containing JSON. Here's a short example::
console.print_json('[false, true, null, "foo"]')
You can also *log* json by printing a :class:`~rich.json.JSON` object::
from rich.json import JSON
console.print_json(JSON('["foo", "bar"]'))
Because printing JSON is a common requirement, you may import ``print_json`` from the main namespace::
from rich import print_json
Low level output
----------------
@ -78,6 +96,7 @@ Here's an example::
>>> console.out("Locals", locals())
Rules
-----