# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# #### YAML -> JSON conversion

import yaml

# #### yaml_files/example1.yaml
# ------------------------------------------
#
# ```yaml
# env:
#   - name: INCLUDE_TEST_PIPELINES
#     value: FALSE
#   - name: AIRFLOW_KUBE_NAMESPACE
#     valueFrom:
#       fieldRef:
#         fieldPath: metadata.namespace
#   - name: SQL_ALCHEMY_CONN
#     valueFrom:
#       secretKeyRef:
#         name: airflow-secrets
#         key: sql_alchemy_conn
# ```

with open("yaml_files/example1.yaml", 'r') as stream:
    try:
        yaml1 = yaml.load(stream)
    except yaml.YAMLError as exc:
        print(exc)

import json

print(json.dumps(yaml1, indent=2))

# #### yaml_files/example2.yaml
# ---------
# ```yaml
# invoice: 34843
# date   : '2001-01-23' # JSON doesn't support date data type thats why converted to string
# bill-to: &id001
#     given  : Chris
#     family : Dumars
#     address:
#         lines: |
#             458 Walkman Dr.
#             Suite #292
#         city    : Royal Oak
#         state   : MI
#         postal  : 48046
# ship-to: *id001
# product:
#     - sku         : BL394D
#       quantity    : 4
#       description : Basketball
#       price       : 450.00
#     - sku         : BL4438H
#       quantity    : 1
#       description : Super Hoop
#       price       : 2392.00
# tax  : 251.42
# total: 4443.52
# comments: >
#     Late afternoon is best.
#     Backup contact is Nancy
#     Billsmer @ 338-4338.
# ```

with open("yaml_files/example2.yaml", 'r') as stream:
    try:
        yaml2 = yaml.load(stream)
    except yaml.YAMLError as exc:
        print(exc)

print(json.dumps(yaml2, indent=2))

# #### yaml_files/example3.yaml
# ---
# ```yaml
# env:
#     - DIR: /hello/txt
#     - USER: surendra
#     - PASSWORD: <PASSWORD>
# credentials: >
#     {
#         "key1": "value1"
#         "key2": "value2"
#     }
# temp_key: standard_key
# ```

with open("yaml_files/example3.yaml", 'r') as stream:
    try:
        yaml3 = yaml.load(stream)
    except yaml.YAMLError as exc:
        print(exc)

print(yaml3)

print(yaml3['credentials'])



StarcoderdataJupyterScriptsDedupFiltered