Зачем конвертировать YAML в CSV?
Data sets authored in YAML for human readability - product catalogues, contact lists, test fixtures - often need to reach a spreadsheet, a database, or a reporting tool. .CSV is the universal exchange format for that transfer, accepted by Excel, Google Sheets, and virtually every database importer.
Способы конвертации YAML в CSV
Command line - yq CLI
Run yq -o=csv '.' input.yaml > output.csv after installing yq (free, Windows / macOS / Linux) from github.com/mikefarah/yq.
Python - PyYAML + csv FREE
Install PyYAML via pip, then load with yaml.safe_load() and write rows with the built-in csv.DictWriter.
Python - pandas FREE
After pip install pandas pyyaml, convert in one line: pd.DataFrame(yaml.safe_load(open('input.yaml'))).to_csv('output.csv', index=False).
Об этих форматах
Файл .yaml (или .yml) - это структурированные данные или конфигурация в текстовом формате YAML, используемые для конвейеров CI/CD, Docker Compose, манифестов Kubernetes и настроек…
Открыть детали .YAML →Файл CSV хранит табличные данные в виде обычного текста - по одной строке на запись, значения разделены запятыми (или точкой с запятой в европейских регионах). Его открывает любая…
Открыть детали .CSV →Качество и на что обратить внимание
- Only flat, uniform YAML sequences convert cleanly - nested configs (Kubernetes, Docker Compose, CI pipelines) produce meaningless or empty CSV output.
- YAML comments and type distinctions (integers, booleans) are silently lost; values like
yes,no,on, oroffmay be misread as booleans by older parsers. - Column order follows the key order of the first record; if you need a specific order, define
fieldnamesexplicitly or reorder keys in the source file.
Часто задаваемые вопросы
My YAML has nested objects. Can I still convert it?
Does this work with multi-document YAML files separated by `---`?
yq eval-all '[.]' input.yaml before passing to the CSV output flag; the documents must still be uniform flat sequences.