forked from yukinarit/pyserde
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonfile.py
More file actions
49 lines (35 loc) · 682 Bytes
/
jsonfile.py
File metadata and controls
49 lines (35 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
jsonfile.py
Make an http request to JSON WebAPI.
Usage:
$ poetry install
$ poetry run python jsonfile.py
"""
from dataclasses import dataclass
from typing import List, Optional
import requests
from serde import serde
from serde.json import from_json
@serde
@dataclass
class Slide:
title: str
type: str
items: Optional[List[str]]
@serde
@dataclass
class Slideshow:
author: str
date: str
slides: List[Slide]
title: str
@serde
@dataclass
class Data:
slideshow: Slideshow
def main():
text = requests.get('https://httpbin.org/json').text
data = from_json(Data, text)
print(data)
if __name__ == '__main__':
main()