Skip to content

Commit

Permalink
Merge pull request #146 from nbuilding/bug-fix
Browse files Browse the repository at this point in the history
Closes #143
  • Loading branch information
SheepTester authored Apr 29, 2021
2 parents f1ca1e8 + ae4674a commit 6d5433b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
22 changes: 21 additions & 1 deletion python/libraries/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,31 @@ def parseSafe(string):
except:
return None

def convert_float_to_int(value):
if isinstance(value, float):
if value % 1 == 0:
value = round(value)
elif isinstance(value, dict):
for i in value.keys():
if isinstance(value[i], dict) or isinstance(value[i], list):
value[i] = convert_float_to_int(value[i])
elif isinstance(value[i], float):
if value[i] % 1 == 0:
value[i] = round(value[i])
elif isinstance(value, list):
for i in range(len(value)):
if isinstance(value[i], dict) or isinstance(value[i], list):
value[i] = convert_float_to_int(value[i])
elif isinstance(value[i], float):
if value[i] % 1 == 0:
value[i] = round(value[i])

return value

# TODO: Formatting options?
# TODO: Convert NaN and infinities to null, per spec.
def stringify(json_value):
return json.dumps(json_to_python(json_value))
return json.dumps(convert_float_to_int(json_to_python(json_value)))


def _values():
Expand Down
20 changes: 19 additions & 1 deletion python/run.n
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
print("eee" + \n)
print(\n + "eee")
print(split(\{.}, "this.is.a.test"))
print(split(\{.}, "this.is.a.test"))
import json

print(json.stringify(json.array([json.object(mapFrom([
("op", json.number(2.0)),
("d", json.object(mapFrom([
("token", json.string("dingus")),
("intents", json.number(512.0)),
("properties", json.object(mapFrom([
("$os", json.string("windows")),
("$browser", json.string("none")),
("$device", json.string("none"))
]))),
])))
])),
json.number(1.0),
json.string("ping")])))

print(json.stringify(json.string("bingus")))

0 comments on commit 6d5433b

Please sign in to comment.