japc 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- japc/__init__.py +1 -0
- japc/core.py +57 -0
- japc-0.1.0.dist-info/METADATA +22 -0
- japc-0.1.0.dist-info/RECORD +6 -0
- japc-0.1.0.dist-info/WHEEL +5 -0
- japc-0.1.0.dist-info/top_level.txt +1 -0
japc/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import tojson, savejson, fromjson, loadjson, autojson
|
japc/core.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from datetime import datetime, date
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def converter(obj):
|
|
7
|
+
#Pandas part
|
|
8
|
+
if hasattr(obj, "to_dict") and callable(obj.to_dict):
|
|
9
|
+
return obj.to_dict(orient="records")
|
|
10
|
+
#numpy part
|
|
11
|
+
if hasattr(obj, "item") and callable(obj.item):
|
|
12
|
+
return obj.item()
|
|
13
|
+
|
|
14
|
+
#custom classes
|
|
15
|
+
if hasattr(obj, "__dict__"):
|
|
16
|
+
return obj.__dict__
|
|
17
|
+
|
|
18
|
+
#sets and tuples
|
|
19
|
+
if isinstance(obj, (set, tuple)):
|
|
20
|
+
return list(obj)
|
|
21
|
+
|
|
22
|
+
#dates and timestamps
|
|
23
|
+
if isinstance(obj, (datetime, date)):
|
|
24
|
+
return obj.isoformat()
|
|
25
|
+
|
|
26
|
+
#fallback to text
|
|
27
|
+
return str(obj)
|
|
28
|
+
|
|
29
|
+
def tojson(anything, indent=4):
|
|
30
|
+
return json.dumps(anything,default=converter, indent=indent)
|
|
31
|
+
|
|
32
|
+
def savejson(anything, filename="output.json", indent=4):
|
|
33
|
+
with open(filename, "w") as f:
|
|
34
|
+
f.write(tojson(anything,indent=indent))
|
|
35
|
+
|
|
36
|
+
def fromjson(json_string):
|
|
37
|
+
return json.loads(json_string)
|
|
38
|
+
|
|
39
|
+
def loadjson(filename="output.json"):
|
|
40
|
+
with open(filename, "r") as f:
|
|
41
|
+
return json.load(f)
|
|
42
|
+
|
|
43
|
+
class autojson:
|
|
44
|
+
def tojson(self, indent=4):
|
|
45
|
+
return tojson(self, indent=indent)
|
|
46
|
+
|
|
47
|
+
def savejson(self, filename="output.json", indent=4):
|
|
48
|
+
savejson(self, filename,indent=indent)
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def fromjson(cls, json_string):
|
|
52
|
+
data = fromjson(json_string)
|
|
53
|
+
return cls(**data)
|
|
54
|
+
@classmethod
|
|
55
|
+
def loadjson(cls, filename="output.json"):
|
|
56
|
+
data = loadjson(filename)
|
|
57
|
+
return cls(**data)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: japc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Automatically convert Python objects, sets, dates, and DataFrames to JSON.
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="https://github.com/mehliciouson/japc_python_library/blob/main/JAPC%20logo.png?raw=true" width="250">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
Created by mehliciouson.
|
|
14
|
+
|
|
15
|
+
Welcome to japc, Json Automatic Python Converter.
|
|
16
|
+
To use this library after you have downloaded
|
|
17
|
+
and imported it, you'll need to master 4 functions
|
|
18
|
+
I implemented into the code. These are "tojson",
|
|
19
|
+
"savejson", "fromjson", and "loadjson". You can
|
|
20
|
+
find out more about these via this Google Doc: https://docs.google.com/document/d/14E4jTr07UtxhvLIZ3tHtVJQeehvZ0wchQuI2eznjGzY/edit?tab=t.0
|
|
21
|
+
|
|
22
|
+
Made with love on Pycharm :)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
japc/__init__.py,sha256=-Sg-WZMuXj0IfmmBGoSGuTdkB7XnugaSt_cP6fbiAPg,66
|
|
2
|
+
japc/core.py,sha256=a1g6w9i0XGFat0xlafgb885H0m_retS2qSFI5Dn7Rm8,1497
|
|
3
|
+
japc-0.1.0.dist-info/METADATA,sha256=Bm_0oSzOp4sn4LyxmB-jKrj5iWURIy1R92b6u3tOVZs,801
|
|
4
|
+
japc-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
5
|
+
japc-0.1.0.dist-info/top_level.txt,sha256=yg3qxOxJqwmbuLZzYE7ZYXJzEKWdoxfMjZWWzw1Nn2E,5
|
|
6
|
+
japc-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
japc
|