Skip to content

Commit

Permalink
fixes things
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashvin-Ranjan committed Apr 29, 2021
1 parent b28e008 commit ae4674a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
26 changes: 15 additions & 11 deletions python/libraries/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,21 @@ def parseSafe(string):
def convert_float_to_int(value):
if isinstance(value, float):
if value % 1 == 0:
return round(value)
return value
elif not isinstance(value, dict):
return value

for i in value.keys():
if isinstance(value[i], dict):
value[i] = convert_float_to_int(value[i])
elif isinstance(value[i], float):
if value[i] % 1 == 0:
value[i] = round(value[i])
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

Expand Down
8 changes: 5 additions & 3 deletions python/run.n
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ print(\n + "eee")
print(split(\{.}, "this.is.a.test"))
import json

print(json.stringify(json.object(mapFrom([
print(json.stringify(json.array([json.object(mapFrom([
("op", json.number(2.0)),
("d", json.object(mapFrom([
("token", json.string("dingus")),
Expand All @@ -14,6 +14,8 @@ print(json.stringify(json.object(mapFrom([
("$device", json.string("none"))
]))),
])))
]))))
])),
json.number(1.0),
json.string("ping")])))

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

0 comments on commit ae4674a

Please sign in to comment.