Skip to content

Commit

Permalink
Add convert str2object (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpintaric55334 authored Sep 7, 2023
1 parent 6000bbb commit 9fdeb79
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions e2e/convert_test/test_str2object1/file1
Original file line number Diff line number Diff line change
@@ -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"
Empty file.
8 changes: 8 additions & 0 deletions e2e/convert_test/test_str2object1/test.yml
Original file line number Diff line number Diff line change
@@ -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}}}
9 changes: 9 additions & 0 deletions python/convert.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9fdeb79

Please sign in to comment.