We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
st.json collapse parameter
_(Note, you don't have to fill out every section here. They're just here for guidance. That said, nicely detailed feature requests are more likely to get eng attention sooner)_

### Problem

Have a parameter for st.json(body, collapse) where the default is `False` but you can set it to `True`. This would allow developers to choose if the json file is expanded or collapsed when rendered on the Streamlit app.

Requested by a community member, link to forum post: 
https://discuss.streamlit.io/t/json-collapse-option/17159

### Solution

**MVP:** a parameter to set the view of a json file on the first render in Streamlit



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `e2e/scripts/st_json.py`
Content:
```
1 # Copyright 2018-2022 Streamlit Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import streamlit as st
16 
17 data = {"foo": "bar"}
18 st.json(data)
19
```

Path: `lib/streamlit/elements/json.py`
Content:
```
1 # Copyright 2018-2022 Streamlit Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import json
16 from typing import cast
17 
18 import streamlit
19 from streamlit.proto.Json_pb2 import Json as JsonProto
20 from streamlit.state import AutoSessionState
21 
22 
23 class JsonMixin:
24     def json(self, body):
25         """Display object or string as a pretty-printed JSON string.
26 
27         Parameters
28         ----------
29         body : Object or str
30             The object to print as JSON. All referenced objects should be
31             serializable to JSON as well. If object is a string, we assume it
32             contains serialized JSON.
33 
34         Example
35         -------
36         >>> st.json({
37         ...     'foo': 'bar',
38         ...     'baz': 'boz',
39         ...     'stuff': [
40         ...         'stuff 1',
41         ...         'stuff 2',
42         ...         'stuff 3',
43         ...         'stuff 5',
44         ...     ],
45         ... })
46 
47         .. output::
48            https://share.streamlit.io/streamlit/docs/main/python/api-examples-source/data.json.py
49            height: 385px
50 
51         """
52         import streamlit as st
53 
54         if isinstance(body, AutoSessionState):
55             body = body.to_dict()
56 
57         if not isinstance(body, str):
58             try:
59                 body = json.dumps(body, default=repr)
60             except TypeError as err:
61                 st.warning(
62                     "Warning: this data structure was not fully serializable as "
63                     "JSON due to one or more unexpected keys.  (Error was: %s)" % err
64                 )
65                 body = json.dumps(body, skipkeys=True, default=repr)
66 
67         json_proto = JsonProto()
68         json_proto.body = body
69         return self.dg._enqueue("json", json_proto)
70 
71     @property
72     def dg(self) -> "streamlit.delta_generator.DeltaGenerator":
73         """Get our DeltaGenerator."""
74         return cast("streamlit.delta_generator.DeltaGenerator", self)
75
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/e2e/scripts/st_json.py b/e2e/scripts/st_json.py
--- a/e2e/scripts/st_json.py
+++ b/e2e/scripts/st_json.py
@@ -16,3 +16,4 @@
 
 data = {"foo": "bar"}
 st.json(data)
+st.json(data, expanded=False)
diff --git a/lib/streamlit/elements/json.py b/lib/streamlit/elements/json.py
--- a/lib/streamlit/elements/json.py
+++ b/lib/streamlit/elements/json.py
@@ -21,7 +21,12 @@
 
 
 class JsonMixin:
-    def json(self, body):
+    def json(
+        self,
+        body,
+        *,  # keyword-only arguments:
+        expanded=True,
+    ):
         """Display object or string as a pretty-printed JSON string.
 
         Parameters
@@ -31,6 +36,11 @@
             serializable to JSON as well. If object is a string, we assume it
             contains serialized JSON.
 
+        expanded : bool
+            An optional boolean that allows the user to set whether the initial
+            state of this json element should be expanded. Defaults to True.
+            This argument can only be supplied by keyword.
+
         Example
         -------
         >>> st.json({
@@ -66,6 +76,7 @@
 
         json_proto = JsonProto()
         json_proto.body = body
+        json_proto.expanded = expanded
         return self.dg._enqueue("json", json_proto)
 
     @property

{"golden_diff": "diff --git a/e2e/scripts/st_json.py b/e2e/scripts/st_json.py\n--- a/e2e/scripts/st_json.py\n+++ b/e2e/scripts/st_json.py\n@@ -16,3 +16,4 @@\n \n data = {\"foo\": \"bar\"}\n st.json(data)\n+st.json(data, expanded=False)\ndiff --git a/lib/streamlit/elements/json.py b/lib/streamlit/elements/json.py\n--- a/lib/streamlit/elements/json.py\n+++ b/lib/streamlit/elements/json.py\n@@ -21,7 +21,12 @@\n \n \n class JsonMixin:\n-    def json(self, body):\n+    def json(\n+        self,\n+        body,\n+        *,  # keyword-only arguments:\n+        expanded=True,\n+    ):\n         \"\"\"Display object or string as a pretty-printed JSON string.\n \n         Parameters\n@@ -31,6 +36,11 @@\n             serializable to JSON as well. If object is a string, we assume it\n             contains serialized JSON.\n \n+        expanded : bool\n+            An optional boolean that allows the user to set whether the initial\n+            state of this json element should be expanded. Defaults to True.\n+            This argument can only be supplied by keyword.\n+\n         Example\n         -------\n         >>> st.json({\n@@ -66,6 +76,7 @@\n \n         json_proto = JsonProto()\n         json_proto.body = body\n+        json_proto.expanded = expanded\n         return self.dg._enqueue(\"json\", json_proto)\n \n     @property\n", "issue": "st.json collapse parameter\n_(Note, you don't have to fill out every section here. They're just here for guidance. That said, nicely detailed feature requests are more likely to get eng attention sooner)_\r\n\r\n### Problem\r\n\r\nHave a parameter for st.json(body, collapse) where the default is `False` but you can set it to `True`. This would allow developers to choose if the json file is expanded or collapsed when rendered on the Streamlit app.\r\n\r\nRequested by a community member, link to forum post: \r\nhttps://discuss.streamlit.io/t/json-collapse-option/17159\r\n\r\n### Solution\r\n\r\n**MVP:** a parameter to set the view of a json file on the first render in Streamlit\r\n\r\n\n", "before_files": [{"content": "# Copyright 2018-2022 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport streamlit as st\n\ndata = {\"foo\": \"bar\"}\nst.json(data)\n", "path": "e2e/scripts/st_json.py"}, {"content": "# Copyright 2018-2022 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport json\nfrom typing import cast\n\nimport streamlit\nfrom streamlit.proto.Json_pb2 import Json as JsonProto\nfrom streamlit.state import AutoSessionState\n\n\nclass JsonMixin:\n    def json(self, body):\n        \"\"\"Display object or string as a pretty-printed JSON string.\n\n        Parameters\n        ----------\n        body : Object or str\n            The object to print as JSON. All referenced objects should be\n            serializable to JSON as well. If object is a string, we assume it\n            contains serialized JSON.\n\n        Example\n        -------\n        >>> st.json({\n        ...     'foo': 'bar',\n        ...     'baz': 'boz',\n        ...     'stuff': [\n        ...         'stuff 1',\n        ...         'stuff 2',\n        ...         'stuff 3',\n        ...         'stuff 5',\n        ...     ],\n        ... })\n\n        .. output::\n           https://share.streamlit.io/streamlit/docs/main/python/api-examples-source/data.json.py\n           height: 385px\n\n        \"\"\"\n        import streamlit as st\n\n        if isinstance(body, AutoSessionState):\n            body = body.to_dict()\n\n        if not isinstance(body, str):\n            try:\n                body = json.dumps(body, default=repr)\n            except TypeError as err:\n                st.warning(\n                    \"Warning: this data structure was not fully serializable as \"\n                    \"JSON due to one or more unexpected keys.  (Error was: %s)\" % err\n                )\n                body = json.dumps(body, skipkeys=True, default=repr)\n\n        json_proto = JsonProto()\n        json_proto.body = body\n        return self.dg._enqueue(\"json\", json_proto)\n\n    @property\n    def dg(self) -> \"streamlit.delta_generator.DeltaGenerator\":\n        \"\"\"Get our DeltaGenerator.\"\"\"\n        return cast(\"streamlit.delta_generator.DeltaGenerator\", self)\n", "path": "lib/streamlit/elements/json.py"}], "after_files": [{"content": "# Copyright 2018-2022 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport streamlit as st\n\ndata = {\"foo\": \"bar\"}\nst.json(data)\nst.json(data, expanded=False)\n", "path": "e2e/scripts/st_json.py"}, {"content": "# Copyright 2018-2022 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport json\nfrom typing import cast\n\nimport streamlit\nfrom streamlit.proto.Json_pb2 import Json as JsonProto\nfrom streamlit.state import AutoSessionState\n\n\nclass JsonMixin:\n    def json(\n        self,\n        body,\n        *,  # keyword-only arguments:\n        expanded=True,\n    ):\n        \"\"\"Display object or string as a pretty-printed JSON string.\n\n        Parameters\n        ----------\n        body : Object or str\n            The object to print as JSON. All referenced objects should be\n            serializable to JSON as well. If object is a string, we assume it\n            contains serialized JSON.\n\n        expanded : bool\n            An optional boolean that allows the user to set whether the initial\n            state of this json element should be expanded. Defaults to True.\n            This argument can only be supplied by keyword.\n\n        Example\n        -------\n        >>> st.json({\n        ...     'foo': 'bar',\n        ...     'baz': 'boz',\n        ...     'stuff': [\n        ...         'stuff 1',\n        ...         'stuff 2',\n        ...         'stuff 3',\n        ...         'stuff 5',\n        ...     ],\n        ... })\n\n        .. output::\n           https://share.streamlit.io/streamlit/docs/main/python/api-examples-source/data.json.py\n           height: 385px\n\n        \"\"\"\n        import streamlit as st\n\n        if isinstance(body, AutoSessionState):\n            body = body.to_dict()\n\n        if not isinstance(body, str):\n            try:\n                body = json.dumps(body, default=repr)\n            except TypeError as err:\n                st.warning(\n                    \"Warning: this data structure was not fully serializable as \"\n                    \"JSON due to one or more unexpected keys.  (Error was: %s)\" % err\n                )\n                body = json.dumps(body, skipkeys=True, default=repr)\n\n        json_proto = JsonProto()\n        json_proto.body = body\n        json_proto.expanded = expanded\n        return self.dg._enqueue(\"json\", json_proto)\n\n    @property\n    def dg(self) -> \"streamlit.delta_generator.DeltaGenerator\":\n        \"\"\"Get our DeltaGenerator.\"\"\"\n        return cast(\"streamlit.delta_generator.DeltaGenerator\", self)\n", "path": "lib/streamlit/elements/json.py"}]}