惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
U
Unit 42
Vercel News
Vercel News
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
C
Check Point Blog
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
博客园_首页
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
Last Week in AI
Last Week in AI
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
V
Visual Studio Blog
小众软件
小众软件

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Convert JSON to YAML (and Back) Without Writing a ...
Tahmid · 2026-05-03 · via DEV Community

You're staring at a JSON API response and you need to paste it into a Kubernetes ConfigMap. Or your colleague sent you a YAML Helm values file and your integration test expects JSON. Either way, manually rewriting the format is tedious, error-prone, and a genuine waste of your afternoon.

This is one of those tasks that sounds simple but hides dozens of small traps: indentation levels, quoted strings that need to stay quoted, booleans that change meaning, and nested arrays that look completely different in each format. Let's fix it properly.

Why JSON and YAML Keep Colliding

JSON and YAML represent the same data model — key-value pairs, arrays, nested objects — but they express it differently. JSON uses braces and brackets; YAML uses indentation and dashes. This makes them structurally compatible but visually incompatible.

The collision happens most often in these real-world scenarios:

  • API responses → Kubernetes manifests. You fetch config data from an API (JSON) and need to embed it in a ConfigMap or Secret (YAML).
  • GitHub Actions / CI pipelines. Workflow files are YAML, but tool configs (ESLint, Prettier, TypeScript) often live in JSON.
  • Helm chart values. Default values are YAML; your templating logic might generate JSON alongside them.
  • Ansible playbooks. Variables defined in JSON need to flow into YAML playbook tasks.

The Conversion Is Mechanical — But Still Fiddly

Here's what the same data looks like in both formats:

JSON:

{
  "server": {
    "host": "api.example.com",
    "port": 8080,
    "tls": true
  },
  "retries": 3,
  "tags": ["production", "us-east-1"]
}

Enter fullscreen mode Exit fullscreen mode

YAML equivalent:

server:
  host: api.example.com
  port: 8080
  tls: true
retries: 3
tags:
  - production
  - us-east-1

Enter fullscreen mode Exit fullscreen mode

Notice the changes: no braces, no quotes around plain strings, arrays become dash-prefixed lists, and the entire structure depends on consistent indentation. One wrong space and your YAML parser throws a fit.

Going the other direction is just as mechanical — but converting by hand still risks mistakes, especially with deeply nested objects.

Converting in the Browser: The Fast Path

Instead of writing conversion code every time, the JSON to YAML Converter handles this in your browser. Paste your JSON on the left, get clean YAML on the right. No sign-up, nothing leaves your browser.

Before converting, make sure your JSON is valid. Compacted API responses or copied-from-logs JSON often have hidden issues — trailing commas, unescaped characters, or single quotes instead of double. Running it through the JSON Beautifier & Validator first formats and validates it in one step, so you're not feeding broken JSON into a converter and wondering why the output looks wrong.

A Real-World Example: Kubernetes ConfigMap

Let's say you have this JSON config coming out of a deployment pipeline:

{
  "database": {
    "host": "postgres.internal",
    "port": 5432,
    "name": "app_production",
    "ssl_mode": "require"
  },
  "cache": {
    "ttl": 300,
    "max_size": 1000
  },
  "feature_flags": {
    "new_checkout": true,
    "beta_search": false
  }
}

Enter fullscreen mode Exit fullscreen mode

After conversion, you get YAML you can drop directly into a Kubernetes ConfigMap:

database:
  host: postgres.internal
  port: 5432
  name: app_production
  ssl_mode: require
cache:
  ttl: 300
  max_size: 1000
feature_flags:
  new_checkout: true
  beta_search: false

Enter fullscreen mode Exit fullscreen mode

Clean, indented, and ready to embed. The tool handles the structural mapping — you just verify the output makes sense.

Going the Other Way: YAML Back to JSON

The reverse conversion matters just as much. Your GitHub Actions workflow file is YAML; you want to parse specific values in a script that expects JSON. Or a colleague sends you an Ansible vars file and your test harness is JSON-only.

The same JSON to YAML Converter supports bidirectional conversion — paste YAML in the YAML panel and get JSON back.

One thing to watch for when going YAML → JSON: YAML has native support for timestamps, multi-line strings (| and > blocks), and anchors/aliases (& and *). These don't have direct JSON equivalents, so they get serialized as plain strings or resolved inline. If your YAML uses these features heavily, review the JSON output carefully before using it downstream.

When to Write the Conversion in Code

For a one-off config tweak, the browser tool is the fastest path. But if you're converting as part of a build pipeline or automation script, you'll want code. Here's the idiomatic approach in a couple of common languages:

Python:

import json, yaml

with open("config.json") as f:
    data = json.load(f)

with open("config.yaml", "w") as f:
    yaml.dump(data, f, default_flow_style=False)

Enter fullscreen mode Exit fullscreen mode

Node.js (with js-yaml):

const fs = require('fs');
const yaml = require('js-yaml');

const data = JSON.parse(fs.readFileSync('config.json', 'utf8'));
fs.writeFileSync('config.yaml', yaml.dump(data));

Enter fullscreen mode Exit fullscreen mode

For interactive exploration or debugging — especially when you're unsure why a converted file looks off — the browser tool remains the quickest feedback loop even if you have automation in place.

Further Reading

If you're curious about where JSON and YAML differ beyond syntax — data type handling, comment support, schema strictness — the JSON vs YAML comparison page goes deeper on the structural tradeoffs between the two formats.

What Format Mismatch Do You Hit Most?

I'm curious — is it mostly the API → config file direction that catches you out, or is YAML → JSON (for testing or scripting) the bigger pain point in your workflow? Drop a comment below.


Free tools used in this post: