Convert configuration values without rounding identifiers
Admin ·
When an identifier and an account balance sit next to each other in a configuration file, their digits can look similar even though the two fields need different types.
Check an ID and a decimal
Convert {"id":"007","count":9007199254740993,"rate":0.1234567890123456789} to YAML. The generated YAML quotes the ID. It writes count and rate as numeric tokens using their original digits. Convert that YAML back to JSON and inspect the three values before loading them into another program. Some consumers round numbers when they read them.
RFC 8259 — JSON data interchange formatYAML 1.2.2 specification
Expand a shared setting
Give a YAML key named primary the value &ports [80, 443]. On the next line give secondary the value *ports. Both JSON keys receive the array [80,443]. JSON has no syntax for naming a shared array. An alias cycle therefore produces a diagnostic.
Compare the outputs
Toggle Compact JSON and convert again. The reported byte count includes the UTF-8 bytes of the result. Indentation affects the count, while the arrays, strings and numbers keep their values.
Keep a serial number when converting YAML to JSON
Choose YAML to JSON. Inspect the resulting scalar types before importing them into another program. An inventory serial may look numeric even when its leading zeros carry information.
serial: "0007"
quantity: 7
enabled: false- The JSON serial has quotes around 0007. The quantity is the number 7 and enabled is the boolean false. If your destination requires each value as a string, make that change explicitly in the input schema.
Common questions
Are YAML comments transferred into JSON?
Comments have no JSON value. They disappear when the converter writes the data as JSON.
Can I convert a map with an integer key?
Quote the key in YAML if it represents a string. A JSON object requires string keys, so the converter reports an error for an integer key.
Sources
Put it into practice.
Related guides
- Checking YAML mapping keys and anchor references
- Preserving CSV and TSV cells in YAML
- Keeping IDs and nested data in CSV
- Telling YAML comments apart from literal text
- Check Exact IDs and Date Text in YAML
- Compare Parsed JSON and YAML by Path
- Check YAML Value Types in a TOON Export
- Keep Dotenv Values as Strings in YAML
- Merge a YAML Overlay and Check Sequence Changes