diff --git a/tests/test_apigateway.py b/tests/test_apigateway.py index a0adf3949..18cea5f5a 100644 --- a/tests/test_apigateway.py +++ b/tests/test_apigateway.py @@ -37,7 +37,7 @@ def test_schema(self): Schema=d ) model.validate() - self.assertEqual(model.properties['Schema'], '{"c": "d"}') + self.assertEqual(model.properties['Schema'], {"c": "d"}) # Check invalid Schema type with self.assertRaises(TypeError): diff --git a/tests/test_cloudwatch.py b/tests/test_cloudwatch.py index cc281a79d..459f69265 100644 --- a/tests/test_cloudwatch.py +++ b/tests/test_cloudwatch.py @@ -26,7 +26,7 @@ def test_dashboard(self): DashboardBody=d ) dashboard.validate() - self.assertEqual(dashboard.properties['DashboardBody'], '{"c": "d"}') + self.assertEqual(dashboard.properties['DashboardBody'], {"c": "d"}) # Check invalid Dashboard type with self.assertRaises(TypeError): diff --git a/troposphere/validators.py b/troposphere/validators.py index b6e1ef34c..a2250ec79 100644 --- a/troposphere/validators.py +++ b/troposphere/validators.py @@ -224,11 +224,16 @@ def json_checker(name, prop): # Verify it is a valid json string json.loads(prop) return prop - elif isinstance(prop, dict): - # Convert the dict to a basestring - return json.dumps(prop) elif isinstance(prop, AWSHelperFn): return prop + elif isinstance(prop, dict): + # Recursively validate JSON + for attr, attr_val in prop.items(): + if isinstance(attr_val, basestring): + json.dumps(attr_val) + elif isinstance(attr_val, dict): + prop[attr] = json_checker(attr, attr_val) + return prop else: raise ValueError("%s must be a str or dict" % name)