JSON Reference¶
See the JSON guide for usage examples.
Bases: Gradient
Render JSON text with a gradient layered over Rich's JSON formatting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json
|
str
|
A JSON string to format. |
required |
indent
|
int | str | None
|
Indent size, or a string, passed to Rich. |
2
|
highlight
|
bool
|
Whether Rich should syntax-highlight the output. |
True
|
skip_keys
|
bool
|
Skip non-basic dict keys instead of raising. |
False
|
ensure_ascii
|
bool
|
Escape non-ASCII characters. |
False
|
check_circular
|
bool
|
Check for circular references. |
True
|
allow_nan
|
bool
|
Allow NaN and infinity values. |
True
|
default
|
Callable[[Any], Any] | None
|
Optional serializer for unsupported objects. |
None
|
sort_keys
|
bool
|
Whether to sort dictionary keys. |
False
|
colors
|
Sequence[ColorType] | None
|
Foreground gradient color stops. |
None
|
bg_colors
|
Sequence[ColorType] | None
|
Background gradient color stops. |
None
|
rainbow
|
bool
|
Whether to generate a rainbow palette. |
False
|
hues
|
int
|
Number of auto-generated hues. |
5
|
repeat_scale
|
float | None
|
Gradient repeat scale; |
None
|
expand
|
bool
|
Whether the gradient frame expands. |
True
|
justify
|
AlignMethod
|
Horizontal alignment. |
'left'
|
vertical_justify
|
VerticalAlignMethod
|
Vertical alignment. |
'middle'
|
console
|
Console | None
|
Optional Rich console. |
None
|
highlight_words
|
HighlightWordsType | None
|
Word highlight configuration. |
None
|
highlight_regex
|
HighlightRegexType | None
|
Regex highlight configuration. |
None
|
Source code in src/rich_gradient/json.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
json
property
¶
Return the underlying Rich JSON renderable.
__init__(json, *, indent=2, highlight=True, skip_keys=False, ensure_ascii=False, check_circular=True, allow_nan=True, default=None, sort_keys=False, colors=None, bg_colors=None, rainbow=False, hues=5, repeat_scale=None, expand=True, justify='left', vertical_justify='middle', console=None, highlight_words=None, highlight_regex=None)
¶
Initialize a gradient-enabled Rich JSON renderable.
Source code in src/rich_gradient/json.py
from_data(data, **kwargs)
classmethod
¶
Build a gradient JSON renderable from a Python object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Object to serialize to JSON. |
required |
**kwargs
|
Any
|
Forwarded to the constructor (and the Rich serializer
options |
{}
|