Repository: aws-cloudformation/cfn-lint

Issue:
E0001 for a validate template in latest version but not 0.21.0
*cfn-lint version: (0.21.1)*

*Description of issue.*

With this cfn template:

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  ServerLamdaRole:
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action:
          - sts:AssumeRole
          Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
        Version: 2012-10-17
      Path: /
    Type: AWS::IAM::Role
```

We got the following error using latest version(`0.21.1`):

```
E0001 Error transforming template: datetime.date(2012, 10, 17) is not JSON serializable
cfn.yml:1:1
```

However, when using cfn-lint(`0.21.0`), this template is correctly validated:

```
{𝞿/RO-1092⁁ncy? ~/.xia/sha/sta/sam}cfn-lint --version && cfn-lint cfn.yml && echo "here"
cfn-lint 0.21.0
here
```



Discussion:
Tested the above with `0.21.2` as well, same `E0001` error:

```
∇{𝞿/RO-1092⁁ncy? ~/.xia/sha/sta/sam}cfn-lint --version && cfn-lint cfn.yml && echo "here"
cfn-lint 0.21.2
E0001 Error transforming template: datetime.date(2012, 10, 17) is not JSON serializable
cfn.yml:1:1
```

Was not expecting another version after this mornings release so the original title is not totally up to date, sorry about that.

Resolving patch:
diff --git a/src/cfnlint/helpers.py b/src/cfnlint/helpers.py
--- a/src/cfnlint/helpers.py
+++ b/src/cfnlint/helpers.py
@@ -19,6 +19,7 @@
 import json
 import os
 import imp
+import datetime
 import logging
 import re
 import inspect
@@ -227,7 +228,11 @@ def initialize_specs():
 
 def format_json_string(json_string):
     """ Format the given JSON string"""
-    return json.dumps(json_string, indent=2, sort_keys=True, separators=(',', ': '))
+    def converter(o):  # pylint: disable=R1710
+        """ Help convert date/time into strings """
+        if isinstance(o, datetime.datetime):
+            return o.__str__()
+    return json.dumps(json_string, indent=2, sort_keys=True, separators=(',', ': '), default=converter)
 
 def load_plugins(directory):
     """Load plugins"""


Test patch:
diff --git a/test/module/helpers/test_format_json.py b/test/module/helpers/test_format_json.py
new file mode 100644
--- /dev/null
+++ b/test/module/helpers/test_format_json.py
@@ -0,0 +1,49 @@
+"""
+  Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy of this
+  software and associated documentation files (the "Software"), to deal in the Software
+  without restriction, including without limitation the rights to use, copy, modify,
+  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+  permit persons to whom the Software is furnished to do so.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""
+import json
+import datetime
+from cfnlint.helpers import format_json_string
+from testlib.testcase import BaseTestCase
+
+
+class TestFormatJson(BaseTestCase):
+    """Test Dumping JSON objects """
+
+    def test_success_run(self):
+        """Test success run"""
+        obj = {
+            'Key': {
+                'SubKey': 'Value',
+                'Date': datetime.datetime(2010, 9, 9)
+            },
+            'List': [
+                {'SubKey': 'AnotherValue'}
+            ]
+        }
+        success = """{
+  "Key": {
+    "Date": "2010-09-09 00:00:00",
+    "SubKey": "Value"
+  },
+  "List": [
+    {
+      "SubKey": "AnotherValue"
+    }
+  ]
+}"""
+        results = format_json_string(obj)
+        self.assertEqual(success, results)