
Converting JSON to YAML Without Losing Types or Quotes
Convert JSON to YAML with a YAML library so strings like yes, 3.10 and 02134 keep their quotes, and see what string formatting does to the same data.
Tag
49 posts

Convert JSON to YAML with a YAML library so strings like yes, 3.10 and 02134 keep their quotes, and see what string formatting does to the same data.

Convert YAML to JSON with PyYAML and json, and handle the cases that break it: dates, sets, integer keys, NaN, anchors, several documents and complex keys.

yq converts YAML to JSON and back in one command. The same file gave different JSON in yq and PyYAML, and a big integer made yq fail. Flags and traps.

A working guide to moving data between JSON and MongoDB: types, import flags, Extended JSON exports, round trips, flattening, nested queries, validation.

Convert JSON to CSV with pandas and the csv module, and avoid the traps: Python repr in cells, True and False, ragged keys, Excel encoding and formula cells.

A working guide to converting JSON to CSV, XML, YAML, Excel, SQL and Markdown and back: what each format cannot hold, a 23 field round trip test, and checks.

Build one internal model and two small renderers, negotiate the format with the Accept header, and test that both carry the same data on awkward cases.

A step-by-step plan for moving an XML service to JSON without breaking consumers: freeze, map, run both, measure, announce a date and retire.

Generic converters guess at lists, attributes and mixed text. Write a small mapping with explicit rules so the JSON stays predictable for every record.

JSON keys can be any string and XML names cannot. Make legal names from spaces and leading digits, write arrays as repeated elements, and mark null.

XML has attributes, repeated children and mixed text, and JSON has objects and arrays. Where the mapping is lossy, what xmltodict does, and the fixes.

pandas, Miller and csvlook turn a CSV into a Markdown table, and each breaks on a pipe or a newline. pandas wrote 12.50 as 12.5 and csvlook 02134 as 2,134.