인셔셔RSS 관심 있는 블로그, 뉴스, 기술 정보를 효율적으로 추적하고 읽으세요
원문 읽기 InertiaRSS에서 열기

추천 피드

博客园 - 司徒正美
V
V2EX
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
月光博客
月光博客
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI

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 Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
Python에서 예쁘게 포맷된 JSON을 다시 읽을 수 있도록 만들기
Yair Lenga · 2026-05-24 · via DEV Community
Cover image for Making Pretty-Printed JSON Readable Again in Python

Yair Lenga

대부분의 JSON 직렬화 도구는 두 가지 선택지만 제공합니다:

  • 컴팩트 머신 출력:
{"a":{"b":{"c":"abc"}},"x":{"y":{"z":"xyz"}}}

전체 화면 모드로 전환 전체 화면 모드 종료

  • 또는 완전히 확장된 “보기 좋게 출력”:
{
  "a": {
    "b": {
      "c": "abc"
    }
  },
  "x": {
    "y": {
      "z": "xyz"
    }
  }
}

전체 화면 모드로 전환 전체 화면 모드 종료

나는 중간의 어떤 것을 원했습니다: 첫 번째는 인간이 스캔하기 어렵고, 두 번째는 실제 세계의 중첩된 데이터에서 매우 수식적인 문장이 됩니다.

아이디어

나는 jsonfold이라는 작은 파이썬 모듈을 작성했습니다. 파이썬의 JSON 직렬화를 바꾸는 대신, json.dump() 출력 위에 가벼운 후처리 필터로 작동합니다.

포맷터는 선택적으로:

  • 작은 컨테이너들을 한 줄로 돌아놓고,
  • 짧은 스칼라 시퀀스들을 포장하고,
  • 큰 또는 복잡한 구조들을 확장状态로 유지합니다.

예시 출력:

{
  "a": { "b": { "c": "abc" } },
  "x": { "y": { "z": "xyz" } }
}

전체 화면 모드로 입력 전체 화면 모드 종료

왜 이 접근 방식인가요?

재작성하고 싶지 않았습니다 - 많은 좋은 시리얼라이저들이 있습니다 (내장 시리얼라이저 포함)json.dump()) 단순한 데이터 구조부터 효율적으로 처리할 수 있는 것들(list/dict) 사용자 지정 클래스 및 Python@dataclass객체를 사용하여 전환을 수행하고 출력 레이아웃을 맞춤 설정합니다.

흥미로운 부분은 포맷터가 하는 일입니다안녕하세요JSON 스트림을 다시 파싱합니다. 파일과 유사한 객체를 둘러싼 스트리밍 래퍼로 작동합니다.

json.dump(obj, JSONFoldWriter(fp), indent=2)

전체 화면 모드 입력 전체 화면 모드 종료

그러므로 큰 문서를 고정된 메모리 사용량과 선형 처리 시간으로 처리할 수 있습니다. 이 접근 방식은 대부분의 기존 시리얼라이저와 작동합니다. 또한 json.dump(), json.dumps()용 래퍼를 제공합니다.

from jsonfold import dumps

data = {
    "a": {"b": {"c": "abc"}},
    "x": {"y": {"z": "xyz"}},
}

print(dumps(data))

전체 화면 모드 입력 전체 화면 모드 종료

개인화

포맷터는 다음을 제어할 수 있습니다:

  • 최대 줄 너비,
  • 폴딩 깊이,
  • 압축 적극성,
  • 배열/객체 제한.

그래서 보수적인 포맷팅과 더 적극적인 압축 사이에서 선택할 수 있습니다.

전체 기사:

중간 (패이월 없음):스트리밍 JSON 포맷터는 기존 시리얼라이저와 함께 작동합니다

최소 사용법

jsonfold.pyGitHub 프로젝트

import jsonfold
import sys
data = {
    "meta": {"version": 1, "ok": True},
    "ids": [1, 2, 3, 4, 5],
    "items": [{"id": 1, "name": "alpha"}, {"id": 2, "name": "beta"}],
}
# compact can be: default, low, med, high, max
jsonfold.dump(data, sys.stdout, compact="default")

Enter fullscreen mode Exit fullscreen mode

GitHub 프로젝트

저장소: https://github.com/yairlenga/jsonfold

파이썬 구현은 아래에 있습니다python 디렉토리.

다른 구현은 JavaScript, Java, C, ...에 대한 기사를 다룰 예정입니다 - GitHub 프로젝트를 주시하거나 Medium에서 기사를 구독하세요.