zerohertzLib.util.json ¶
Classes:
| Name | Description |
|---|---|
Json | JSON 형식 file을 읽고 사용하기 위한 class |
JsonDir | 입력된 경로에 존재하는 JSON 형식 file들을 읽고 사용하기 위한 class |
Functions:
| Name | Description |
|---|---|
write_json | JSON (JavaScript Object Notation)을 작성하는 function |
Json ¶
Json(path: str | None = None)
JSON 형식 file을 읽고 사용하기 위한 class
객체 생성 시 path 를 입력하지 않을 시 현재 경로에 존재하는 JSON file을 읽고 path 를 경로로 입력하면 해당 경로에 존재하는 JSON file을 읽는다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | None | JSON file의 경로 | None |
Attributes:
| Name | Type | Description |
|---|---|---|
name | JSON file 이름 | |
keys | 직렬화된 JSON의 key 값들 |
Examples:
>>> js = zz.util.Json()
>>> js["title"]
'[v0.2.3] Release'
>>> key = js._get_key("color")
>>> key
'labels/LIST/color'
>>> js._get_value(key)
'd73a4a'
>>> js.name
'65.json'
>>> js.keys
['url', 'id', ..., 'assignees/LIST/login', ..., 'active_lock_reason']
Methods:
| Name | Description |
|---|---|
__getitem__ | JSON file에서 key에 해당하는 값을 반환 |
__len__ | JSON file의 길이를 반환 |
get |
|
tree | JSON의 구조를 출력하는 method |
Source code in zerohertzLib/util/json.py
__get_keys ¶
Source code in zerohertzLib/util/json.py
__getitem__ ¶
_get_key ¶
_get_keys ¶
_get_value ¶
get ¶
Json._get_key 로 생성된 key 값을 입력 받아 value return
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | 읽어온 JSON file에서 불러올 key 값 (깊이 무관) | required |
Returns:
| Type | Description |
|---|---|
Any | Key에 따른 value |
Examples:
>>> js["title"]
'[v0.2.3] Release'
>>> js.get("title")
'[v0.2.3] Release'
>>> js["color"]
Traceback:
File "<stdin>", line 1, in <module>
File "/home/zerohertz/Zerohertz/zerohertzLib/zerohertzLib/util/json.py", line 107, in __getitem__
KeyError: 'color'
>>> js.get("color")
'd73a4a'
Source code in zerohertzLib/util/json.py
tree ¶
JSON의 구조를 출력하는 method
Examples:
>>> js.tree()
├── url
...
├── user
│ ├── login
...
│ └── site_admin
├── body
...
├── assignee
│ ├── login
...
│ └── site_admin
├── assignees
│ └── LIST
│ ├── login
...
│ └── site_admin
...
└── active_lock_reason
Source code in zerohertzLib/util/json.py
JsonDir ¶
JsonDir(path: str = '')
입력된 경로에 존재하는 JSON 형식 file들을 읽고 사용하기 위한 class
객체 생성 시 path 를 입력하지 않을 시 현재 경로에 존재하는 JSON file들을 읽는다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | JSON file의 경로 | '' |
Attributes:
| Name | Type | Description |
|---|---|---|
name | 읽어온 JSON file의 이름들 | |
data | File 이름에 따른 |
Examples:
>>> jsd = zz.util.JsonDir()
100%|█████████████| 5/5 [00:00<00:00, 3640.26it/s]
>>> len(jsd)
5
>>> jsd[0]
<zerohertzLib.util.json.Json object at 0x7f2562b83d00>
>>> jsd[0]["title"]
'[v0.2.3] Release'
>>> jsd._get_key("color")
'labels/LIST/color'
Methods:
| Name | Description |
|---|---|
__getitem__ | Index를 사용하여 JSON file에 접근 |
__len__ | JSON file의 길이를 반환 |
tree | JSON의 구조를 출력하는 method |
unique | 읽어온 JSON data들의 유일한 값을 return하는 method |
Source code in zerohertzLib/util/json.py
__getitem__ ¶
_get_key ¶
tree ¶
unique ¶
읽어온 JSON data들의 유일한 값을 return하는 method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | 읽어온 JSON file에서 불러올 key 값 | required |
Returns:
| Type | Description |
|---|---|
set[str] | Key에 따른 유일한 값들의 집합 |
Examples:
>>> jsd.unique("label")
{'Zerohertz:docs', 'Zerohertz:dev-v0.2.3', 'Zerohertz:docs-v0.2.2'}
>>> jsd.unique("sha")
{'dfd53a0bfc73221dbe96d5e44a49c524d5a8596b', 'bc33235424e89cbbf23434b2a824ea068d167c7d', '97f52f9b81ba885fe69b9726632e580f5cba94be', '768c7711f94af0be00cd55e0ce7b892465cfa64a', '97e103788359f0361f4ec0e138a14218f28eddd4'}
Source code in zerohertzLib/util/json.py
write_json ¶
JSON (JavaScript Object Notation)을 작성하는 function
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | dict[Any, Any] | list[dict[Any, Any]] | 입력 data (header 포함 무관) | required |
path | str | 출력될 JSON file의 경로 및 이름 | required |
Returns:
| Type | Description |
|---|---|
str | File의 절대 경로 |
Examples:
>>> zz.util.write_json([{"id": "4169", "전투력": 4209, "정보": ["아무", "거나"]}]*100, "zerohertzLib/star_craft")
'/.../star_craft.json'
[
{
"id": "4169",
"전투력": 4209,
"정보": [
"아무",
"거나"
]
},
{
"id": "4169",
"전투력": 4209,
"정보": [
"아무",
"거나"
]
},
...