diff --git a/graphene/core/types/custom_scalars.py b/graphene/core/types/custom_scalars.py index bd33df76..c1346c0a 100644 --- a/graphene/core/types/custom_scalars.py +++ b/graphene/core/types/custom_scalars.py @@ -16,11 +16,11 @@ class JSONString(Scalar): @staticmethod def parse_literal(node): if isinstance(node, ast.StringValue): - return json.dumps(node.value) + return json.loads(node.value) @staticmethod def parse_value(value): - return json.dumps(value) + return json.loads(value) class DateTime(Scalar): diff --git a/graphene/core/types/tests/test_custom_scalars.py b/graphene/core/types/tests/test_custom_scalars.py index 28012b36..31cb7855 100644 --- a/graphene/core/types/tests/test_custom_scalars.py +++ b/graphene/core/types/tests/test_custom_scalars.py @@ -1,7 +1,7 @@ import iso8601 from graphql.language.ast import StringValue -from ..custom_scalars import DateTime +from ..custom_scalars import DateTime, JSONString def test_date_time(): @@ -24,3 +24,16 @@ def test_date_time(): node = StringValue(test_iso_string) test_dt = DateTime.parse_literal(node) check_datetime(test_dt) + + +def test_json_string(): + test_json_string = '{"foo": "bar"}' + + test_object = JSONString().parse_value(test_json_string) + assert test_object == {'foo': 'bar'} + + assert JSONString.serialize(test_object) == test_json_string + + node = StringValue(test_json_string) + test_object = JSONString.parse_literal(node) + assert test_object == {'foo': 'bar'}