diff --git a/e2e/convert_test/test_str2object1/file1 b/e2e/convert_test/test_str2object1/file1 new file mode 100644 index 000000000..c6dc46576 --- /dev/null +++ b/e2e/convert_test/test_str2object1/file1 @@ -0,0 +1,4 @@ +"_id","_labels","a","b","prop","did_it","_start","_end","_type" +"0",":Dog","3","[""1"", ""2"", 3]","2","","","","" +"1",":Human","","[[""1"",{""key"": 5}]]","","yes","","","" +"5",":Cat","","{""prop"": {""prop2"": {""key"": 10}}}","","","0","1","loves" diff --git a/e2e/convert_test/test_str2object1/input.cyp b/e2e/convert_test/test_str2object1/input.cyp new file mode 100644 index 000000000..e69de29bb diff --git a/e2e/convert_test/test_str2object1/test.yml b/e2e/convert_test/test_str2object1/test.yml new file mode 100644 index 000000000..938976cbf --- /dev/null +++ b/e2e/convert_test/test_str2object1/test.yml @@ -0,0 +1,8 @@ +query: > + LOAD CSV FROM "/_file1" WITH header AS row + RETURN convert.str2object(row.b) AS list; + +output: + - list: [ "1","2", 3] + - list: [["1",{"key": 5}]] + - list: {"prop": {"prop2": {"key": 10}}} diff --git a/python/convert.py b/python/convert.py new file mode 100644 index 000000000..6db93c8c6 --- /dev/null +++ b/python/convert.py @@ -0,0 +1,9 @@ +import mgp +from json import loads + + +@mgp.function +def str2object(string: str) -> mgp.Any: + if string: + return loads(string) + return None