We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Configurable SecretStr
This issue revisits this comment https://github.com/samuelcolvin/pydantic/issues/462#issuecomment-480326378 by @tiangolo.

I think it would be a good idea that there is a standard way of getting secrets exported for propagation to other services.

This is not something that tends to happen in three tier apps where e.g. the db creds are secret but rather a case that happens _a lot_ when dealing with microservice architectures wherein request payloads may serialize and deserialize multiple times through the end to end request lifecycle.

`.json()` to me is semantically like `.export` and as such defaulting to revealing secret makes sense. But that would be a breaking change.

Other approaches:

- `.json(reveal_secrets=True)`
- `.export()`

But maybe we can take the breaking change path via https://github.com/samuelcolvin/pydantic/issues/576 and then:

- `.json(keep_secrets=True)`

To be clear I don't see `.json` as being something used for logging. Something like `structlog` would work with `pydantic.dict()` instead:

```
log.info('something', data=model.dict())
```

I _think_ `.dict` defaulting to maintaining secrets seems right. But we could have, too:

```
log.info('something', data=model.dict(reveal_secrets=True))
```

But than we should make considerations around API consistency across methods and ensure usability is good overall, not just per case.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `docs/examples/types_secret_types.py`
Content:
```
1 from pydantic import BaseModel, SecretStr, SecretBytes, ValidationError
2 
3 class SimpleModel(BaseModel):
4     password: SecretStr
5     password_bytes: SecretBytes
6 
7 sm = SimpleModel(password='IAmSensitive', password_bytes=b'IAmSensitiveBytes')
8 
9 # Standard access methods will not display the secret
10 print(sm)
11 print(sm.password)
12 print(sm.json())
13 
14 # Use get_secret_value method to see the secret's content.
15 print(sm.password.get_secret_value())
16 print(sm.password_bytes.get_secret_value())
17 
18 try:
19     SimpleModel(password=[1, 2, 3], password_bytes=[1, 2, 3])
20 except ValidationError as e:
21     print(e)
22
```
--- 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/docs/examples/types_secret_types.py b/docs/examples/types_secret_types.py
--- a/docs/examples/types_secret_types.py
+++ b/docs/examples/types_secret_types.py
@@ -9,6 +9,7 @@
 # Standard access methods will not display the secret
 print(sm)
 print(sm.password)
+print(sm.dict())
 print(sm.json())
 
 # Use get_secret_value method to see the secret's content.
@@ -19,3 +20,26 @@
     SimpleModel(password=[1, 2, 3], password_bytes=[1, 2, 3])
 except ValidationError as e:
     print(e)
+
+# If you want the secret to be dumped as plain-text using the json method,
+# you can use json_encoders in the Config class.
+class SimpleModelDumpable(BaseModel):
+    password: SecretStr
+    password_bytes: SecretBytes
+
+    class Config:
+        json_encoders = {
+            SecretStr: lambda v: v.get_secret_value() if v else None,
+            SecretBytes: lambda v: v.get_secret_value() if v else None,
+        }
+
+sm2 = SimpleModelDumpable(password='IAmSensitive', 
+                          password_bytes=b'IAmSensitiveBytes')
+
+# Standard access methods will not display the secret
+print(sm2)
+print(sm2.password)
+print(sm2.dict())
+
+# But the json method will
+print(sm2.json())

{"golden_diff": "diff --git a/docs/examples/types_secret_types.py b/docs/examples/types_secret_types.py\n--- a/docs/examples/types_secret_types.py\n+++ b/docs/examples/types_secret_types.py\n@@ -9,6 +9,7 @@\n # Standard access methods will not display the secret\n print(sm)\n print(sm.password)\n+print(sm.dict())\n print(sm.json())\n \n # Use get_secret_value method to see the secret's content.\n@@ -19,3 +20,26 @@\n     SimpleModel(password=[1, 2, 3], password_bytes=[1, 2, 3])\n except ValidationError as e:\n     print(e)\n+\n+# If you want the secret to be dumped as plain-text using the json method,\n+# you can use json_encoders in the Config class.\n+class SimpleModelDumpable(BaseModel):\n+    password: SecretStr\n+    password_bytes: SecretBytes\n+\n+    class Config:\n+        json_encoders = {\n+            SecretStr: lambda v: v.get_secret_value() if v else None,\n+            SecretBytes: lambda v: v.get_secret_value() if v else None,\n+        }\n+\n+sm2 = SimpleModelDumpable(password='IAmSensitive', \n+                          password_bytes=b'IAmSensitiveBytes')\n+\n+# Standard access methods will not display the secret\n+print(sm2)\n+print(sm2.password)\n+print(sm2.dict())\n+\n+# But the json method will\n+print(sm2.json())\n", "issue": "Configurable SecretStr\nThis issue revisits this comment https://github.com/samuelcolvin/pydantic/issues/462#issuecomment-480326378 by @tiangolo.\r\n\r\nI think it would be a good idea that there is a standard way of getting secrets exported for propagation to other services.\r\n\r\nThis is not something that tends to happen in three tier apps where e.g. the db creds are secret but rather a case that happens _a lot_ when dealing with microservice architectures wherein request payloads may serialize and deserialize multiple times through the end to end request lifecycle.\r\n\r\n`.json()` to me is semantically like `.export` and as such defaulting to revealing secret makes sense. But that would be a breaking change.\r\n\r\nOther approaches:\r\n\r\n- `.json(reveal_secrets=True)`\r\n- `.export()`\r\n\r\nBut maybe we can take the breaking change path via https://github.com/samuelcolvin/pydantic/issues/576 and then:\r\n\r\n- `.json(keep_secrets=True)`\r\n\r\nTo be clear I don't see `.json` as being something used for logging. Something like `structlog` would work with `pydantic.dict()` instead:\r\n\r\n```\r\nlog.info('something', data=model.dict())\r\n```\r\n\r\nI _think_ `.dict` defaulting to maintaining secrets seems right. But we could have, too:\r\n\r\n```\r\nlog.info('something', data=model.dict(reveal_secrets=True))\r\n```\r\n\r\nBut than we should make considerations around API consistency across methods and ensure usability is good overall, not just per case.\n", "before_files": [{"content": "from pydantic import BaseModel, SecretStr, SecretBytes, ValidationError\n\nclass SimpleModel(BaseModel):\n    password: SecretStr\n    password_bytes: SecretBytes\n\nsm = SimpleModel(password='IAmSensitive', password_bytes=b'IAmSensitiveBytes')\n\n# Standard access methods will not display the secret\nprint(sm)\nprint(sm.password)\nprint(sm.json())\n\n# Use get_secret_value method to see the secret's content.\nprint(sm.password.get_secret_value())\nprint(sm.password_bytes.get_secret_value())\n\ntry:\n    SimpleModel(password=[1, 2, 3], password_bytes=[1, 2, 3])\nexcept ValidationError as e:\n    print(e)\n", "path": "docs/examples/types_secret_types.py"}], "after_files": [{"content": "from pydantic import BaseModel, SecretStr, SecretBytes, ValidationError\n\nclass SimpleModel(BaseModel):\n    password: SecretStr\n    password_bytes: SecretBytes\n\nsm = SimpleModel(password='IAmSensitive', password_bytes=b'IAmSensitiveBytes')\n\n# Standard access methods will not display the secret\nprint(sm)\nprint(sm.password)\nprint(sm.dict())\nprint(sm.json())\n\n# Use get_secret_value method to see the secret's content.\nprint(sm.password.get_secret_value())\nprint(sm.password_bytes.get_secret_value())\n\ntry:\n    SimpleModel(password=[1, 2, 3], password_bytes=[1, 2, 3])\nexcept ValidationError as e:\n    print(e)\n\n# If you want the secret to be dumped as plain-text using the json method,\n# you can use json_encoders in the Config class.\nclass SimpleModelDumpable(BaseModel):\n    password: SecretStr\n    password_bytes: SecretBytes\n\n    class Config:\n        json_encoders = {\n            SecretStr: lambda v: v.get_secret_value() if v else None,\n            SecretBytes: lambda v: v.get_secret_value() if v else None,\n        }\n\nsm2 = SimpleModelDumpable(password='IAmSensitive', \n                          password_bytes=b'IAmSensitiveBytes')\n\n# Standard access methods will not display the secret\nprint(sm2)\nprint(sm2.password)\nprint(sm2.dict())\n\n# But the json method will\nprint(sm2.json())\n", "path": "docs/examples/types_secret_types.py"}]}