Repository: conda/conda

Issue:
conda config --show --json fails with TypeError is not JSON serializable.
```
$conda config --show --json
{
  "error": "Traceback (most recent call last):\n  File \"C:\\Anaconda\\lib\\site-packages\\conda\\exceptions.py\", line 479, in conda_exception_handler\n    return_value = func(*args, **kwargs)\n  File \"C:\\Anaconda\\lib\\site-packages\\conda\\cli\\main.py\", line 145, in _main\n    exit_code = args.func(args, p)\n  File \"C:\\Anaconda\\lib\\site-packages\\conda\\cli\\main_config.py\", line 230, in execute\n    execute_config(args, parser)\n  File \"C:\\Anaconda\\lib\\site-packages\\conda\\cli\\main_config.py\", line 306, in execute_config\n    print(json.dumps(d, sort_keys=True, indent=2, separators=(',', ': ')))\n  File \"C:\\Anaconda\\lib\\json\\__init__.py\", line 251, in dumps\n    sort_keys=sort_keys, **kw).encode(obj)\n  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 209, in encode\n    chunks = list(chunks)\n
  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 434, in _iterencode\n    for chunk in _iterencode_dict(o, _current_indent_level):\n  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 408, in _iterencode_dict\n    for chunk in chunks:\n  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 442, in _iterencode\n    o = _default(o)\n  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 184, in default\n    raise TypeError(repr(o) + \" is not JSON serializable\")\nTypeError: Channel(scheme=https, auth=None, location=conda.anaconda.org, token=None, name=None, platform=None, package_filename=None) is not JSON serializable\n"
}
```
expanding the traceback for better readability:
```
Traceback (most recent call last):
  File \"C:\\Anaconda\\lib\\site-packages\\conda\\exceptions.py\", line 479, in conda_exception_handler
    return_value = func(*args, **kwargs)
  File \"C:\\Anaconda\\lib\\site-packages\\conda\\cli\\main.py\", line 145, in _main
    exit_code = args.func(args, p)
  File \"C:\\Anaconda\\lib\\site-packages\\conda\\cli\\main_config.py\", line 230, in execute
    execute_config(args, parser)
  File \"C:\\Anaconda\\lib\\site-packages\\conda\\cli\\main_config.py\", line 306, in execute_config
    print(json.dumps(d, sort_keys=True, indent=2, separators=(',', ': ')))
  File \"C:\\Anaconda\\lib\\json\\__init__.py\", line 251, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 209, in encode
    chunks = list(chunks)

  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 408, in _iterencode_dict
    for chunk in chunks:
  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 442, in _iterencode
    o = _default(o)
  File \"C:\\Anaconda\\lib\\json\\encoder.py\", line 184, in default
    raise TypeError(repr(o) + \" is not JSON serializable\")
TypeError: Channel(scheme=https, auth=None, location=conda.anaconda.org, token=None, name=None, platform=None, package_filename=None) is not JSON serializable
```

`conda config --show` works fine.

Tested with:
```
Current conda install:

               platform : win-64
          conda version : 4.2.11
       conda is private : False
      conda-env version : 4.2.11
    conda-build version : 1.21.3
         python version : 2.7.12.final.0
       requests version : 2.11.1
```
and 
```
Current conda install:

               platform : linux-64
          conda version : 4.2.12
       conda is private : False
      conda-env version : 4.2.12
    conda-build version : 1.20.0
         python version : 2.7.12.final.0
       requests version : 2.9.1
```
`conda config --json --show-sources` works fine. 


Discussion:

Resolving patch:
diff --git a/conda/cli/main_config.py b/conda/cli/main_config.py
--- a/conda/cli/main_config.py
+++ b/conda/cli/main_config.py
@@ -13,6 +13,7 @@
 from .common import (Completer, add_parser_json, stdout_json_success)
 from .. import CondaError
 from .._vendor.auxlib.compat import isiterable
+from .._vendor.auxlib.entity import EntityEncoder
 from .._vendor.auxlib.type_coercion import boolify
 from ..base.context import context
 from ..common.configuration import pretty_list, pretty_map
@@ -303,7 +304,8 @@ def execute_config(args, parser):
                                            'verbosity',
                                            )))
         if context.json:
-            print(json.dumps(d, sort_keys=True, indent=2, separators=(',', ': ')))
+            print(json.dumps(d, sort_keys=True, indent=2, separators=(',', ': '),
+                  cls=EntityEncoder))
         else:
             print('\n'.join(format_dict(d)))
         context.validate_configuration()
diff --git a/conda/models/channel.py b/conda/models/channel.py
--- a/conda/models/channel.py
+++ b/conda/models/channel.py
@@ -335,6 +335,9 @@ def __nonzero__(self):
     def __bool__(self):
         return self.__nonzero__()
 
+    def __json__(self):
+        return self.__dict__
+
     @property
     def url_channel_wtf(self):
         return self.base_url, self.canonical_name


Test patch: