Skip to content

Commit

Permalink
Make indent param in console.print_json compatible to json.dumps inde…
Browse files Browse the repository at this point in the history
…nt param
skshetry committed Nov 7, 2021
1 parent 654f702 commit a3f8e04
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions rich/console.py
Original file line number Diff line number Diff line change
@@ -1625,7 +1625,7 @@ def print_json(
json: Optional[str] = None,
*,
data: Any = None,
indent: int = 2,
indent: Union[None, int, str] = 2,
highlight: bool = True,
skip_keys: bool = False,
ensure_ascii: bool = True,
@@ -1639,7 +1639,7 @@ def print_json(
Args:
json (Optional[str]): A string containing JSON.
data (Any): If json is not supplied, then encode this data.
indent (int, optional): Number of spaces to indent. Defaults to 2.
indent (Union[None, int, str], optional): Number of spaces to indent. Defaults to 2.
highlight (bool, optional): Enable highlighting of output: Defaults to True.
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
10 changes: 5 additions & 5 deletions rich/json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from json import loads, dumps
from typing import Any, Callable, Optional
from typing import Any, Callable, Optional, Union

from .text import Text
from .highlighter import JSONHighlighter, NullHighlighter
@@ -10,7 +10,7 @@ class JSON:
Args:
json (str): JSON encoded data.
indent (int, optional): Number of characters to indent by. Defaults to 2.
indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2.
highlight (bool, optional): Enable highlighting. Defaults to True.
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
@@ -24,7 +24,7 @@ class JSON:
def __init__(
self,
json: str,
indent: int = 2,
indent: Union[None, int, str] = 2,
highlight: bool = True,
skip_keys: bool = False,
ensure_ascii: bool = True,
@@ -53,7 +53,7 @@ def __init__(
def from_data(
cls,
data: Any,
indent: int = 2,
indent: Union[None, int, str] = 2,
highlight: bool = True,
skip_keys: bool = False,
ensure_ascii: bool = True,
@@ -66,7 +66,7 @@ def from_data(
Args:
data (Any): An object that may be encoded in to JSON
indent (int, optional): Number of characters to indent by. Defaults to 2.
indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2.
highlight (bool, optional): Enable highlighting. Defaults to True.
default (Callable, optional): Optional callable which will be called for objects that cannot be serialized. Defaults to None.
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.

0 comments on commit a3f8e04

Please sign in to comment.