We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
E2532 - StateMachine Json not parsing when using multi param !Sub
**cfn-lint version:**
```
$ cfn-lint --version
cfn-lint 0.9.1
```
**Description of issue:**
When using `!Sub` with 2 parameters as defined [here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html) then cfn-lint chokes on the parameter being subbed in because technically this is not valid json. This is valid cloud formation though.
 
**Here is basic example showing issue:**
```yaml
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31

Parameters:
  TestParam:
    Type: String

Resources:

  StateMachine:
    Type: AWS::StepFunctions::StateMachine
    Properties:
      StateMachineName: TestStatemachine
      RoleArn: arn:aws:iam::123456789012:role/test-role
      DefinitionString:
        !Sub
      - |
        {
          "StartAt": "FlowChoice",
          "States": {
            "FlowChoice": {
              "Type": "Choice",
              "Choices": [
                {
                  "Variable": "$.sleep",
                  "StringEquals": "true",
                  "Next": "Sleep"
                },
                {
                  "Variable": "$.sleep",
                  "StringEquals": "false",
                  "Next": "Stop"
                }
              ],
              "Default": "Stop"
            },
            "Sleep": {
              "Type": "Wait",
              "Seconds": ${TestParam},   # <--- Not handled!
              "Next": "Stop"
            },
            "Stop": {
              "Type": "Succeed"
            }
          }
        }
      - {TestParam: !Ref TestParam}
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cfnlint/rules/resources/stepfunctions/StateMachine.py`
Content:
```
1 """
2   Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 
4   Permission is hereby granted, free of charge, to any person obtaining a copy of this
5   software and associated documentation files (the "Software"), to deal in the Software
6   without restriction, including without limitation the rights to use, copy, modify,
7   merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
8   permit persons to whom the Software is furnished to do so.
9 
10   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
11   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
12   PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
13   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
14   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
15   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 """
17 import json
18 import six
19 from cfnlint import CloudFormationLintRule
20 from cfnlint import RuleMatch
21 
22 
23 class StateMachine(CloudFormationLintRule):
24     """Check State Machine Definition"""
25     id = 'E2532'
26     shortdesc = 'Check State Machine Definition for proper syntax'
27     description = 'Check the State Machine String Definition to make sure its JSON. ' \
28                   'Validate basic syntax of the file to determine validity.'
29     source_url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html'
30     tags = ['resources', 'stepfunctions']
31 
32     def __init__(self):
33         """Init"""
34         super(StateMachine, self).__init__()
35         self.resource_property_types.append('AWS::StepFunctions::StateMachine')
36 
37     def _check_state_json(self, def_json, state_name, path):
38         """Check State JSON Definition"""
39         matches = []
40 
41         # https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-common-fields.html
42         common_state_keys = [
43             'Next',
44             'End',
45             'Type',
46             'Comment',
47             'InputPath',
48             'OutputPath',
49         ]
50         common_state_required_keys = [
51             'Type',
52         ]
53         state_key_types = {
54             'Pass': ['Result', 'ResultPath'],
55             'Task': ['Resource', 'ResultPath', 'Retry', 'Catch', 'TimeoutSeconds', 'HeartbeatSeconds'],
56             'Choice': ['Choices', 'Default'],
57             'Wait': ['Seconds', 'Timestamp', 'SecondsPath', 'TimestampPath'],
58             'Succeed': [],
59             'Fail': ['Cause', 'Error'],
60             'Parallel': ['Branches', 'ResultPath', 'Retry', 'Catch']
61         }
62         state_required_types = {
63             'Pass': [],
64             'Task': ['Resource'],
65             'Choice': ['Choices'],
66             'Wait': [],
67             'Succeed': [],
68             'Fail': [],
69             'Parallel': ['Branches']
70         }
71 
72         for req_key in common_state_required_keys:
73             if req_key not in def_json:
74                 message = 'State Machine Definition required key (%s) for State (%s) is missing' % (req_key, state_name)
75                 matches.append(RuleMatch(path, message))
76                 return matches
77 
78         state_type = def_json.get('Type')
79 
80         if state_type in state_key_types:
81             for state_key, _ in def_json.items():
82                 if state_key not in common_state_keys + state_key_types.get(state_type, []):
83                     message = 'State Machine Definition key (%s) for State (%s) of Type (%s) is not valid' % (state_key, state_name, state_type)
84                     matches.append(RuleMatch(path, message))
85             for req_key in common_state_required_keys + state_required_types.get(state_type, []):
86                 if req_key not in def_json:
87                     message = 'State Machine Definition required key (%s) for State (%s) of Type (%s) is missing' % (req_key, state_name, state_type)
88                     matches.append(RuleMatch(path, message))
89                     return matches
90         else:
91             message = 'State Machine Definition Type (%s) is not valid' % (state_type)
92             matches.append(RuleMatch(path, message))
93 
94         return matches
95 
96     def _check_definition_json(self, def_json, path):
97         """Check JSON Definition"""
98         matches = []
99 
100         top_level_keys = [
101             'Comment',
102             'StartAt',
103             'TimeoutSeconds',
104             'Version',
105             'States'
106         ]
107         top_level_required_keys = [
108             'StartAt',
109             'States'
110         ]
111         for top_key, _ in def_json.items():
112             if top_key not in top_level_keys:
113                 message = 'State Machine Definition key (%s) is not valid' % top_key
114                 matches.append(RuleMatch(path, message))
115 
116         for req_key in top_level_required_keys:
117             if req_key not in def_json:
118                 message = 'State Machine Definition required key (%s) is missing' % req_key
119                 matches.append(RuleMatch(path, message))
120 
121         for state_name, state_value in def_json.get('States', {}).items():
122             matches.extend(self._check_state_json(state_value, state_name, path))
123         return matches
124 
125     def check_value(self, value, path):
126         """Check Definition Value"""
127         matches = []
128         try:
129             def_json = json.loads(value)
130         # pylint: disable=W0703
131         except Exception as err:
132             message = 'State Machine Definition needs to be formatted as JSON. Error %s' % err
133             matches.append(RuleMatch(path, message))
134             return matches
135 
136         matches.extend(self._check_definition_json(def_json, path))
137         return matches
138 
139     def check_sub(self, value, path):
140         """Check Sub Object"""
141         matches = []
142         if isinstance(value, list):
143             matches.extend(self.check_value(value[0], path))
144         elif isinstance(value, six.string_types):
145             matches.extend(self.check_value(value, path))
146 
147         return matches
148 
149     def match_resource_properties(self, properties, _, path, cfn):
150         """Check CloudFormation Properties"""
151         matches = []
152 
153         matches.extend(
154             cfn.check_value(
155                 obj=properties, key='DefinitionString',
156                 path=path[:],
157                 check_value=self.check_value,
158                 check_sub=self.check_sub
159             ))
160 
161         return matches
162
```
--- 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/src/cfnlint/rules/resources/stepfunctions/StateMachine.py b/src/cfnlint/rules/resources/stepfunctions/StateMachine.py
--- a/src/cfnlint/rules/resources/stepfunctions/StateMachine.py
+++ b/src/cfnlint/rules/resources/stepfunctions/StateMachine.py
@@ -122,15 +122,19 @@
             matches.extend(self._check_state_json(state_value, state_name, path))
         return matches
 
-    def check_value(self, value, path):
+    def check_value(self, value, path, fail_on_loads=True):
         """Check Definition Value"""
         matches = []
         try:
             def_json = json.loads(value)
         # pylint: disable=W0703
         except Exception as err:
-            message = 'State Machine Definition needs to be formatted as JSON. Error %s' % err
-            matches.append(RuleMatch(path, message))
+            if fail_on_loads:
+                message = 'State Machine Definition needs to be formatted as JSON. Error %s' % err
+                matches.append(RuleMatch(path, message))
+                return matches
+
+            self.logger.debug('State Machine definition could not be parsed. Skipping')
             return matches
 
         matches.extend(self._check_definition_json(def_json, path))
@@ -140,9 +144,9 @@
         """Check Sub Object"""
         matches = []
         if isinstance(value, list):
-            matches.extend(self.check_value(value[0], path))
+            matches.extend(self.check_value(value[0], path, False))
         elif isinstance(value, six.string_types):
-            matches.extend(self.check_value(value, path))
+            matches.extend(self.check_value(value, path, False))
 
         return matches

{"golden_diff": "diff --git a/src/cfnlint/rules/resources/stepfunctions/StateMachine.py b/src/cfnlint/rules/resources/stepfunctions/StateMachine.py\n--- a/src/cfnlint/rules/resources/stepfunctions/StateMachine.py\n+++ b/src/cfnlint/rules/resources/stepfunctions/StateMachine.py\n@@ -122,15 +122,19 @@\n             matches.extend(self._check_state_json(state_value, state_name, path))\n         return matches\n \n-    def check_value(self, value, path):\n+    def check_value(self, value, path, fail_on_loads=True):\n         \"\"\"Check Definition Value\"\"\"\n         matches = []\n         try:\n             def_json = json.loads(value)\n         # pylint: disable=W0703\n         except Exception as err:\n-            message = 'State Machine Definition needs to be formatted as JSON. Error %s' % err\n-            matches.append(RuleMatch(path, message))\n+            if fail_on_loads:\n+                message = 'State Machine Definition needs to be formatted as JSON. Error %s' % err\n+                matches.append(RuleMatch(path, message))\n+                return matches\n+\n+            self.logger.debug('State Machine definition could not be parsed. Skipping')\n             return matches\n \n         matches.extend(self._check_definition_json(def_json, path))\n@@ -140,9 +144,9 @@\n         \"\"\"Check Sub Object\"\"\"\n         matches = []\n         if isinstance(value, list):\n-            matches.extend(self.check_value(value[0], path))\n+            matches.extend(self.check_value(value[0], path, False))\n         elif isinstance(value, six.string_types):\n-            matches.extend(self.check_value(value, path))\n+            matches.extend(self.check_value(value, path, False))\n \n         return matches\n", "issue": "E2532 - StateMachine Json not parsing when using multi param !Sub\n**cfn-lint version:**\r\n```\r\n$ cfn-lint --version\r\ncfn-lint 0.9.1\r\n```\r\n**Description of issue:**\r\nWhen using `!Sub` with 2 parameters as defined [here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html) then cfn-lint chokes on the parameter being subbed in because technically this is not valid json. This is valid cloud formation though.\r\n \r\n**Here is basic example showing issue:**\r\n```yaml\r\nAWSTemplateFormatVersion: 2010-09-09\r\nTransform: AWS::Serverless-2016-10-31\r\n\r\nParameters:\r\n  TestParam:\r\n    Type: String\r\n\r\nResources:\r\n\r\n  StateMachine:\r\n    Type: AWS::StepFunctions::StateMachine\r\n    Properties:\r\n      StateMachineName: TestStatemachine\r\n      RoleArn: arn:aws:iam::123456789012:role/test-role\r\n      DefinitionString:\r\n        !Sub\r\n      - |\r\n        {\r\n          \"StartAt\": \"FlowChoice\",\r\n          \"States\": {\r\n            \"FlowChoice\": {\r\n              \"Type\": \"Choice\",\r\n              \"Choices\": [\r\n                {\r\n                  \"Variable\": \"$.sleep\",\r\n                  \"StringEquals\": \"true\",\r\n                  \"Next\": \"Sleep\"\r\n                },\r\n                {\r\n                  \"Variable\": \"$.sleep\",\r\n                  \"StringEquals\": \"false\",\r\n                  \"Next\": \"Stop\"\r\n                }\r\n              ],\r\n              \"Default\": \"Stop\"\r\n            },\r\n            \"Sleep\": {\r\n              \"Type\": \"Wait\",\r\n              \"Seconds\": ${TestParam},   # <--- Not handled!\r\n              \"Next\": \"Stop\"\r\n            },\r\n            \"Stop\": {\r\n              \"Type\": \"Succeed\"\r\n            }\r\n          }\r\n        }\r\n      - {TestParam: !Ref TestParam}\r\n```\r\n\n", "before_files": [{"content": "\"\"\"\n  Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this\n  software and associated documentation files (the \"Software\"), to deal in the Software\n  without restriction, including without limitation the rights to use, copy, modify,\n  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n  permit persons to whom the Software is furnished to do so.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\n  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\n  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\"\"\"\nimport json\nimport six\nfrom cfnlint import CloudFormationLintRule\nfrom cfnlint import RuleMatch\n\n\nclass StateMachine(CloudFormationLintRule):\n    \"\"\"Check State Machine Definition\"\"\"\n    id = 'E2532'\n    shortdesc = 'Check State Machine Definition for proper syntax'\n    description = 'Check the State Machine String Definition to make sure its JSON. ' \\\n                  'Validate basic syntax of the file to determine validity.'\n    source_url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html'\n    tags = ['resources', 'stepfunctions']\n\n    def __init__(self):\n        \"\"\"Init\"\"\"\n        super(StateMachine, self).__init__()\n        self.resource_property_types.append('AWS::StepFunctions::StateMachine')\n\n    def _check_state_json(self, def_json, state_name, path):\n        \"\"\"Check State JSON Definition\"\"\"\n        matches = []\n\n        # https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-common-fields.html\n        common_state_keys = [\n            'Next',\n            'End',\n            'Type',\n            'Comment',\n            'InputPath',\n            'OutputPath',\n        ]\n        common_state_required_keys = [\n            'Type',\n        ]\n        state_key_types = {\n            'Pass': ['Result', 'ResultPath'],\n            'Task': ['Resource', 'ResultPath', 'Retry', 'Catch', 'TimeoutSeconds', 'HeartbeatSeconds'],\n            'Choice': ['Choices', 'Default'],\n            'Wait': ['Seconds', 'Timestamp', 'SecondsPath', 'TimestampPath'],\n            'Succeed': [],\n            'Fail': ['Cause', 'Error'],\n            'Parallel': ['Branches', 'ResultPath', 'Retry', 'Catch']\n        }\n        state_required_types = {\n            'Pass': [],\n            'Task': ['Resource'],\n            'Choice': ['Choices'],\n            'Wait': [],\n            'Succeed': [],\n            'Fail': [],\n            'Parallel': ['Branches']\n        }\n\n        for req_key in common_state_required_keys:\n            if req_key not in def_json:\n                message = 'State Machine Definition required key (%s) for State (%s) is missing' % (req_key, state_name)\n                matches.append(RuleMatch(path, message))\n                return matches\n\n        state_type = def_json.get('Type')\n\n        if state_type in state_key_types:\n            for state_key, _ in def_json.items():\n                if state_key not in common_state_keys + state_key_types.get(state_type, []):\n                    message = 'State Machine Definition key (%s) for State (%s) of Type (%s) is not valid' % (state_key, state_name, state_type)\n                    matches.append(RuleMatch(path, message))\n            for req_key in common_state_required_keys + state_required_types.get(state_type, []):\n                if req_key not in def_json:\n                    message = 'State Machine Definition required key (%s) for State (%s) of Type (%s) is missing' % (req_key, state_name, state_type)\n                    matches.append(RuleMatch(path, message))\n                    return matches\n        else:\n            message = 'State Machine Definition Type (%s) is not valid' % (state_type)\n            matches.append(RuleMatch(path, message))\n\n        return matches\n\n    def _check_definition_json(self, def_json, path):\n        \"\"\"Check JSON Definition\"\"\"\n        matches = []\n\n        top_level_keys = [\n            'Comment',\n            'StartAt',\n            'TimeoutSeconds',\n            'Version',\n            'States'\n        ]\n        top_level_required_keys = [\n            'StartAt',\n            'States'\n        ]\n        for top_key, _ in def_json.items():\n            if top_key not in top_level_keys:\n                message = 'State Machine Definition key (%s) is not valid' % top_key\n                matches.append(RuleMatch(path, message))\n\n        for req_key in top_level_required_keys:\n            if req_key not in def_json:\n                message = 'State Machine Definition required key (%s) is missing' % req_key\n                matches.append(RuleMatch(path, message))\n\n        for state_name, state_value in def_json.get('States', {}).items():\n            matches.extend(self._check_state_json(state_value, state_name, path))\n        return matches\n\n    def check_value(self, value, path):\n        \"\"\"Check Definition Value\"\"\"\n        matches = []\n        try:\n            def_json = json.loads(value)\n        # pylint: disable=W0703\n        except Exception as err:\n            message = 'State Machine Definition needs to be formatted as JSON. Error %s' % err\n            matches.append(RuleMatch(path, message))\n            return matches\n\n        matches.extend(self._check_definition_json(def_json, path))\n        return matches\n\n    def check_sub(self, value, path):\n        \"\"\"Check Sub Object\"\"\"\n        matches = []\n        if isinstance(value, list):\n            matches.extend(self.check_value(value[0], path))\n        elif isinstance(value, six.string_types):\n            matches.extend(self.check_value(value, path))\n\n        return matches\n\n    def match_resource_properties(self, properties, _, path, cfn):\n        \"\"\"Check CloudFormation Properties\"\"\"\n        matches = []\n\n        matches.extend(\n            cfn.check_value(\n                obj=properties, key='DefinitionString',\n                path=path[:],\n                check_value=self.check_value,\n                check_sub=self.check_sub\n            ))\n\n        return matches\n", "path": "src/cfnlint/rules/resources/stepfunctions/StateMachine.py"}], "after_files": [{"content": "\"\"\"\n  Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this\n  software and associated documentation files (the \"Software\"), to deal in the Software\n  without restriction, including without limitation the rights to use, copy, modify,\n  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n  permit persons to whom the Software is furnished to do so.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\n  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\n  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\"\"\"\nimport json\nimport six\nfrom cfnlint import CloudFormationLintRule\nfrom cfnlint import RuleMatch\n\n\nclass StateMachine(CloudFormationLintRule):\n    \"\"\"Check State Machine Definition\"\"\"\n    id = 'E2532'\n    shortdesc = 'Check State Machine Definition for proper syntax'\n    description = 'Check the State Machine String Definition to make sure its JSON. ' \\\n                  'Validate basic syntax of the file to determine validity.'\n    source_url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html'\n    tags = ['resources', 'stepfunctions']\n\n    def __init__(self):\n        \"\"\"Init\"\"\"\n        super(StateMachine, self).__init__()\n        self.resource_property_types.append('AWS::StepFunctions::StateMachine')\n\n    def _check_state_json(self, def_json, state_name, path):\n        \"\"\"Check State JSON Definition\"\"\"\n        matches = []\n\n        # https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-common-fields.html\n        common_state_keys = [\n            'Next',\n            'End',\n            'Type',\n            'Comment',\n            'InputPath',\n            'OutputPath',\n        ]\n        common_state_required_keys = [\n            'Type',\n        ]\n        state_key_types = {\n            'Pass': ['Result', 'ResultPath'],\n            'Task': ['Resource', 'ResultPath', 'Retry', 'Catch', 'TimeoutSeconds', 'HeartbeatSeconds'],\n            'Choice': ['Choices', 'Default'],\n            'Wait': ['Seconds', 'Timestamp', 'SecondsPath', 'TimestampPath'],\n            'Succeed': [],\n            'Fail': ['Cause', 'Error'],\n            'Parallel': ['Branches', 'ResultPath', 'Retry', 'Catch']\n        }\n        state_required_types = {\n            'Pass': [],\n            'Task': ['Resource'],\n            'Choice': ['Choices'],\n            'Wait': [],\n            'Succeed': [],\n            'Fail': [],\n            'Parallel': ['Branches']\n        }\n\n        for req_key in common_state_required_keys:\n            if req_key not in def_json:\n                message = 'State Machine Definition required key (%s) for State (%s) is missing' % (req_key, state_name)\n                matches.append(RuleMatch(path, message))\n                return matches\n\n        state_type = def_json.get('Type')\n\n        if state_type in state_key_types:\n            for state_key, _ in def_json.items():\n                if state_key not in common_state_keys + state_key_types.get(state_type, []):\n                    message = 'State Machine Definition key (%s) for State (%s) of Type (%s) is not valid' % (state_key, state_name, state_type)\n                    matches.append(RuleMatch(path, message))\n            for req_key in common_state_required_keys + state_required_types.get(state_type, []):\n                if req_key not in def_json:\n                    message = 'State Machine Definition required key (%s) for State (%s) of Type (%s) is missing' % (req_key, state_name, state_type)\n                    matches.append(RuleMatch(path, message))\n                    return matches\n        else:\n            message = 'State Machine Definition Type (%s) is not valid' % (state_type)\n            matches.append(RuleMatch(path, message))\n\n        return matches\n\n    def _check_definition_json(self, def_json, path):\n        \"\"\"Check JSON Definition\"\"\"\n        matches = []\n\n        top_level_keys = [\n            'Comment',\n            'StartAt',\n            'TimeoutSeconds',\n            'Version',\n            'States'\n        ]\n        top_level_required_keys = [\n            'StartAt',\n            'States'\n        ]\n        for top_key, _ in def_json.items():\n            if top_key not in top_level_keys:\n                message = 'State Machine Definition key (%s) is not valid' % top_key\n                matches.append(RuleMatch(path, message))\n\n        for req_key in top_level_required_keys:\n            if req_key not in def_json:\n                message = 'State Machine Definition required key (%s) is missing' % req_key\n                matches.append(RuleMatch(path, message))\n\n        for state_name, state_value in def_json.get('States', {}).items():\n            matches.extend(self._check_state_json(state_value, state_name, path))\n        return matches\n\n    def check_value(self, value, path, fail_on_loads=True):\n        \"\"\"Check Definition Value\"\"\"\n        matches = []\n        try:\n            def_json = json.loads(value)\n        # pylint: disable=W0703\n        except Exception as err:\n            if fail_on_loads:\n                message = 'State Machine Definition needs to be formatted as JSON. Error %s' % err\n                matches.append(RuleMatch(path, message))\n                return matches\n\n            self.logger.debug('State Machine definition could not be parsed. Skipping')\n            return matches\n\n        matches.extend(self._check_definition_json(def_json, path))\n        return matches\n\n    def check_sub(self, value, path):\n        \"\"\"Check Sub Object\"\"\"\n        matches = []\n        if isinstance(value, list):\n            matches.extend(self.check_value(value[0], path, False))\n        elif isinstance(value, six.string_types):\n            matches.extend(self.check_value(value, path, False))\n\n        return matches\n\n    def match_resource_properties(self, properties, _, path, cfn):\n        \"\"\"Check CloudFormation Properties\"\"\"\n        matches = []\n\n        matches.extend(\n            cfn.check_value(\n                obj=properties, key='DefinitionString',\n                path=path[:],\n                check_value=self.check_value,\n                check_sub=self.check_sub\n            ))\n\n        return matches\n", "path": "src/cfnlint/rules/resources/stepfunctions/StateMachine.py"}]}