Urgent.News

What's breaking now, across thousands of outlets.

Tech

JSON vs YAML: When to Use Which

JSON and YAML can describe the same data, so the choice comes down to who (or what) reads and writes the file. JSON is strict, small, and easy for software to parse. YAML is looser and friendlier for humans to edit. Picking the right one prevents a surprising number of config bugs. The same data, two ways // JSON { "name" : "api" , "ports" : [ 80 , 443 ], "debug" : false , "env" : { "NODE_ENV" :…

JSON and YAML serve the same purpose of describing data, but their differences lie in their readability and ease of use for different users. JSON is strict and compact, making it ideal for software to parse quickly and efficiently. YAML, on the other hand, is more forgiving and user-friendly for humans to edit. When choosing between the two, consider who will be reading and writing the file.

If the data needs to be exchanged between software systems, JSON is the better choice. JSON's strict grammar eliminates ambiguity, and most programming languages have built-in JSON parsers. Machine-generated files like lock files and API responses benefit from JSON's consistency.

Conversely, YAML shines when humans are involved in maintaining the file. Configurations such as Kubernetes manifests, GitHub Actions, Docker Compose, and Ansible are better suited for YAML due to its support for comments and multi-line strings. YAML also handles deeply nested data more gracefully than JSON, and its indentation-based structure makes it easier for humans to read and understand complex data.

However, YAML has its pitfalls. Indentation is crucial in YAML, and any misalignment can silently alter the document's meaning or break it entirely. Unquoted values can also be interpreted as booleans in YAML 1.1, leading to unexpected results. To avoid these issues, always quote values that should remain strings, and use a safe YAML loader to mitigate security risks when loading untrusted data.

In summary, use JSON when software needs to communicate with other software, and opt for YAML when humans are the primary readers and editors of the file. When converting between JSON and YAML, remember that the process is lossless when converting from JSON to YAML, but converting back to JSON may result in loss of comments and anchors. Always re-validate the converted file after any conversion to ensure its integrity.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Regex Cheatsheet for Beginners (With Copy-Paste Examples)

Regular expressions look cryptic at first, but a small set of building blocks covers most real-world tasks: validating input, searching logs, and doing bulk find-and-replace.

  • Dot character . matches any character except newline
  • Character classes like [abc] match specific options
  • Quantifiers specify occurrence counts like , +, ?

Base64 Is Not Encryption (And Other Common Misconceptions)

Base64 shows up everywhere: emails, data URLs, HTTP headers, JWTs. Because the output looks scrambled, it is often mistaken for encryption. It isn't.

  • Base64 is an encoding method, not encryption
  • It converts binary data to text format, reversible by anyone
  • Used for text-only channels, not providing secrecy

Why You Should Remove EXIF Data Before Sharing Photos

Every photo from a phone or camera carries a block of hidden information called EXIF (Exchangeable Image File Format) metadata.

  • Removing EXIF data before sharing photos prevents revealing personal information.
  • EXIF metadata includes device specifics, timestamps, and location data.
  • Use browser-based tools to strip metadata without uploading photos.

How to Decode a JWT Safely (Without Sending It to a Server)

A JSON Web Token (JWT) looks like an opaque blob, but it is just three Base64URL-encoded pieces joined by dots. Anyone who holds the token can read what's inside; no secret key is needed.

  • A JWT consists of three encoded sections linked by dots
  • Header and payload can be decoded into JSON to reveal metadata and claims
  • Signature remains untouched as binary data, do not decode it

More from Saturday 26 September →