Repository: pydantic/pydantic

Issue:
Object of type 'NameEmail' is not JSON serializable
### Checks

* [x] I added a descriptive title to this issue
* [x] I have searched (google, github) for similar issues and couldn't find anything
* [x] I have read and followed [the docs](https://pydantic-docs.helpmanual.io/) and still think this is a bug

<!-- Sorry to sound so draconian, but every second saved replying to issues is time spend improving pydantic :-) -->

# Bug

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
             pydantic version: 1.7.3
            pydantic compiled: True
                 install path: /app/env/lib/python3.8/site-packages/pydantic
               python version: 3.8.5 (default, Jul 28 2020, 12:59:40)  [GCC 9.3.0]
                     platform: Linux-5.8.0-43-generic-x86_64-with-glibc2.29
     optional deps. installed: ['typing-extensions', 'email-validator']

```
<!-- or if you're using pydantic prior to v1.3, manually include: OS, python version and pydantic version -->

<!-- Please read the [docs](https://pydantic-docs.helpmanual.io/) and search through issues to
confirm your bug hasn't already been reported. -->

This issue was mentioned in #462, but was only solved for the case of SecretStr, NameEmail was left unsolved.

<!-- Where possible please include a self-contained code snippet describing your bug: -->

```py
import pydantic

class MyModel(pydantic.BaseModel):
    email: pydantic.NameEmail

MyModel(email="foo <zzz@bar.com>").json()
```
I get:
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pydantic/main.py", line 506, in pydantic.main.BaseModel.json
  File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "pydantic/json.py", line 65, in pydantic.json.pydantic_encoder
TypeError: Object of type 'NameEmail' is not JSON serializable
```


Discussion:
Thanks for reporting. Amazing this has never come up before.

Should be relatively simple to fix in [`pydantic/json.py`](https://github.com/samuelcolvin/pydantic/blob/master/pydantic/json.py), the only tricky thing is dealing with conditional imports.
@samuelcolvin hey I'm trying to fix this bug and I'm encountering the tricky conditional imports thing. Would it be easier to move `NameEmail` to `pydantic/types.py` like `SecretStr`?
Humm, I would prefer not to.

What is the problem? network.py shouldn't import json.py

Resolving patch:
diff --git a/pydantic/json.py b/pydantic/json.py
--- a/pydantic/json.py
+++ b/pydantic/json.py
@@ -17,6 +17,7 @@
     Pattern = re.compile('a').__class__
 
 from .color import Color
+from .networks import NameEmail
 from .types import SecretBytes, SecretStr
 
 __all__ = 'pydantic_encoder', 'custom_pydantic_encoder', 'timedelta_isoformat'
@@ -65,6 +66,7 @@ def decimal_encoder(dec_value: Decimal) -> Union[int, float]:
     IPv6Address: str,
     IPv6Interface: str,
     IPv6Network: str,
+    NameEmail: str,
     Path: str,
     Pattern: lambda o: o.pattern,
     SecretBytes: str,


Test patch:
diff --git a/tests/test_json.py b/tests/test_json.py
--- a/tests/test_json.py
+++ b/tests/test_json.py
@@ -12,7 +12,7 @@
 
 import pytest
 
-from pydantic import BaseModel, create_model
+from pydantic import BaseModel, NameEmail, create_model
 from pydantic.color import Color
 from pydantic.dataclasses import dataclass as pydantic_dataclass
 from pydantic.json import pydantic_encoder, timedelta_isoformat
@@ -35,6 +35,7 @@ class MyEnum(Enum):
         (SecretStr(''), '""'),
         (SecretBytes(b'xyz'), '"**********"'),
         (SecretBytes(b''), '""'),
+        (NameEmail('foo bar', 'foobaR@example.com'), '"foo bar <foobaR@example.com>"'),
         (IPv6Address('::1:0:1'), '"::1:0:1"'),
         (IPv4Interface('192.168.0.0/24'), '"192.168.0.0/24"'),
         (IPv6Interface('2001:db00::/120'), '"2001:db00::/120"'),