Skip to content

Gradio JSON component does not display a formatted JSON string #11592

@anirbanbasu

Description

@anirbanbasu

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions