-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyaml_to_json.py
More file actions
68 lines (55 loc) · 1.33 KB
/
yaml_to_json.py
File metadata and controls
68 lines (55 loc) · 1.33 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Convert YAML to JSON using DocForge API.
Usage: python yaml_to_json.py
"""
import requests
import json
API_URL = "https://docforge-api.vercel.app/api/yaml-json"
yaml_config = """
database:
host: localhost
port: 5432
name: myapp_production
pool:
min: 5
max: 20
redis:
host: localhost
port: 6379
db: 0
server:
port: 3000
cors:
origins:
- https://example.com
- https://app.example.com
methods:
- GET
- POST
- PUT
- DELETE
logging:
level: info
format: json
file: /var/log/app.log
"""
def convert():
response = requests.post(
API_URL,
json={"input": yaml_config, "direction": "yaml-to-json"}
)
if response.status_code != 200:
print(f"Error: {response.status_code}")
print(response.text)
return
result = response.json()
print("=== JSON Output ===")
print(json.dumps(result["output"], indent=2))
# Access nested values
config = result["output"]
print(f"\nDatabase: {config['database']['host']}:{config['database']['port']}/{config['database']['name']}")
print(f"Redis: {config['redis']['host']}:{config['redis']['port']}")
print(f"Server port: {config['server']['port']}")
print(f"CORS origins: {', '.join(config['server']['cors']['origins'])}")
if __name__ == "__main__":
convert()