Skip to content

Commit

Permalink
fix #113 fix missing close symbol (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemia authored Jun 17, 2024
1 parent 76d4337 commit f493e5d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/fuzzy_json/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,17 @@ def state_post_value(input: str, stack: list[str]) -> str | None:
return input[0] + state_object(input[1:], stack)
return None
elif input[0] == "]":
assert stack[-1] == "["
return input[0] + state_post_value(input[1:], stack[:-1])
elif input[0] == "}":
if stack[-1] == "[":
return input[0] + state_post_value(input[1:], stack[:-1])
# NOTE: assume there is missing }
assert stack[-1] == "{"
return input[0] + state_post_object(input[1:], stack[:-1])
return state_post_value("}" + input, stack)
elif input[0] == "}":
if stack[-1] == "{":
return input[0] + state_post_value(input[1:], stack[:-1])
# NOTE: assume there is missing ]
assert stack[-1] == "["
return state_post_value("]" + input, stack)
return None


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"attr1": [
{
"a": "1"
},
{
"a": "2"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"attr1": [
{
"a": 1
},
{
"a": 2
}
]
}
1 change: 1 addition & 0 deletions src/fuzzy_json/tests/test_data/invalid/case6.jsonx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"attr1": [{"a": "1"},{"a": "2"}}
1 change: 1 addition & 0 deletions src/fuzzy_json/tests/test_data/invalid/case7.jsonx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"attr1": [{"a": 1},{"a": 2}}

0 comments on commit f493e5d

Please sign in to comment.