-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
If I supply gr.JSON
with a value
that is a formatted JSON string, such as one output by model_dump_json(indent=4)
on a Pydantic object, the JSON component renders the JSON as one single string losing all the formatting.
My solution is to read that formatted JSON string back using json.loads()
and supplying that information to the value
of gr.JSON
. This seems a bit crazy but it works.
Should I open a PR?
(@nacarino FYI.)
Have you searched existing issues? 🔎
- I have searched and found no existing issues
Reproduction
import gradio as gr
from pydantic import BaseModel
class MyClass(BaseModel):
# ... various fields
myobj = MyClass()
gr.JSON(value=myobj.model_dump_json(indent=4)))
This snippet does not show how to launch the server.
Screenshot
No response
Logs
System Info
Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.35.0
gradio_client version: 1.10.4
------------------------------------------------
gradio dependencies in your environment:
aiofiles: 24.1.0
anyio: 4.9.0
audioop-lts is not installed.
fastapi: 0.116.0
ffmpy: 0.6.0
gradio-client: 1.10.4
groovy: 0.1.2
httpx: 0.28.1
huggingface-hub: 0.33.2
jinja2: 3.1.6
markupsafe: 3.0.2
numpy: 2.2.6
orjson: 3.10.18
packaging: 25.0
pandas: 2.3.1
pillow: 11.3.0
pydantic: 2.11.7
pydub: 0.25.1
python-multipart: 0.0.20
pyyaml: 6.0.2
ruff: 0.12.2
safehttpx: 0.1.6
semantic-version: 2.10.0
starlette: 0.46.2
tomlkit: 0.13.3
typer: 0.16.0
typing-extensions: 4.14.1
urllib3: 2.5.0
uvicorn: 0.35.0
mcp is not installed.
pydantic: 2.11.7
authlib is not installed.
itsdangerous is not installed.
gradio_client dependencies in your environment:
fsspec: 2025.5.1
httpx: 0.28.1
huggingface-hub: 0.33.2
packaging: 25.0
typing-extensions: 4.14.1
websockets: 15.0.1
Severity
I can work around it
Copilot
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working