-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb9219f
commit 742e62b
Showing
6 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import json | ||
import json_fix | ||
|
||
class Test(dict): | ||
def __json__(self): | ||
return 99 | ||
|
||
with open("tests/test4.json", "w") as f: | ||
json.dump([Test()], f) | ||
|
||
# print(f'''test4, pt3, should print and throw error''') | ||
# print(json.dumps(Test())) | ||
|
||
# print(f'''test4, pt4, should print and throw error''') | ||
# print(json.dumps([Test()])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import json | ||
from json import JSONEncoder | ||
from os.path import join | ||
import json_fix | ||
|
||
# same file, or different file | ||
class YOUR_CLASS(dict): | ||
def __json__(self): | ||
# YOUR CUSTOM CODE HERE | ||
# you probably just want to do: | ||
# return self.__dict__ | ||
return "a built-in object that is natually json-able" | ||
|
||
result = [ 1, 2, YOUR_CLASS() ] | ||
with open('tests/test5.json', 'w') as outfile: | ||
json.dump(result, outfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[1, 2, {}] |