πŸ› οΈToolsShed

YAML ↔ JSON Converter

Konversi antara format YAML dan JSON secara instan.

Pertanyaan yang Sering Diajukan

Implementasi Kode

import yaml
import json

# YAML to JSON
yaml_text = """
name: Alice
age: 30
hobbies:
  - reading
  - coding
active: true
"""

data = yaml.safe_load(yaml_text)
json_output = json.dumps(data, indent=2)
print(json_output)

# JSON to YAML
json_text = '{"name": "Bob", "scores": [95, 87, 92]}'
data2 = json.loads(json_text)
yaml_output = yaml.dump(data2, default_flow_style=False, allow_unicode=True)
print(yaml_output)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.