litter
Litter is a Go library that formats data structures into readable, syntactically valid Go literals for debugging and testing. It outputs consistent, sorted snapshots useful for unit test comparisons and handles circular references automatically.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | sanity-io/litter |
| Owner | sanity-io |
| Primary language | Go |
| License | MIT — OSI-approved |
| Stars | 1.7k |
| Forks | 60 |
| Open issues | 17 |
| Latest release | Unknown |
| Last updated | 2026-05-04 |
| Source | https://github.com/sanity-io/litter |
What litter is
A Go pretty-printer that converts arbitrary data structures into literal Go syntax with configurable output (compact/verbose, field filtering, package name stripping). Supports custom dumper interfaces and maintains pointer aliasing for circular reference detection.
Get the litter source
Clone the repository and explore it locally.
git clone https://github.com/sanity-io/litter.gitcd litter# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Configure HidePrivateFields and FieldExclusions upfront to avoid leaking unexported struct fields or generated code artifacts in test snapshots.
- Use local litter.Options for test-specific configurations rather than modifying global Config to prevent test interdependencies.
- Implement the Dumper interface on custom types to control serialization format and avoid verbose or irrelevant field output.
- Plan snapshot file management: decide whether to commit snapshot files to version control and how to handle intentional data structure changes.
- Test circular reference handling explicitly if your domain model contains self-referencing pointers to ensure alias output is stable.
When to avoid it — and what to weigh
- Production Performance Logging — Litter is optimized for readability and consistency, not speed. Avoid using it in hot paths or high-throughput logging scenarios where structured JSON/protobuf serialization is required.
- Cross-Language Serialization — Output is syntactically correct Go only; it cannot be parsed by other languages. For APIs or multi-service systems, use standard formats (JSON, protobuf) instead.
- Handling Very Large Data Structures — Litter holds the entire output in memory (Sdump) or writes synchronously. Extremely large object graphs may consume significant resources; stream-based serialization is a better choice.
- Security-Sensitive Data Output — Litter will dump all visible fields and values. No built-in redaction; sensitive data (passwords, tokens) will appear in plaintext in output if not manually filtered first.
License & commercial use
Licensed under MIT. This is a permissive open-source license permitting commercial use, modification, and distribution with attribution.
MIT license permits unrestricted commercial use. No restrictions on proprietary software integrations. Attribution appreciated but not legally required. No warranty provided; consult internal legal review if including in critical systems.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Good |
| Assessment confidence | High |
Litter performs reflection-based introspection on input data and outputs all visible fields and values. Ensure sensitive data (credentials, keys, PII) is not passed to Litter or is explicitly filtered beforehand using FieldExclusions. No input sanitization or escaping guarantees; output is Go syntax only.
Alternatives to consider
Spew (davecgh/go-spew)
Predecessor project; similar reflection-based pretty-printing. Litter claims to focus on terseness and readability; evaluate if Spew's more verbose output is acceptable for your use case.
encoding/json with MarshalIndent
Standard library alternative for snapshot testing. Output is portable across languages and parseable; less readable for Go-specific types (pointers, unexported fields, nil).
Custom fmt.Sprintf or String() methods
Fine-grained control over output format. More verbose to implement; useful if Litter's defaults do not suit domain models or you need specialized serialization logic.
Build on litter with DEV.co software developers
If your Go team needs readable snapshot testing or better debug output, Litter is a low-friction library to adopt. Review the configuration options and custom Dumper interface to fit your testing practices. MIT license allows immediate commercial use.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
litter FAQ
Can I use Litter output in production code?
Does Litter support custom types (e.g., time.Time, *sql.NullInt64)?
How do I hide sensitive fields from Litter output?
Is Litter performance-critical code or just for testing?
Work with a software development agency
DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If litter is part of your open-source observability roadmap, our team can implement, customize, migrate, and maintain it.
Evaluate Litter for Your Go Testing Pipeline
If your Go team needs readable snapshot testing or better debug output, Litter is a low-friction library to adopt. Review the configuration options and custom Dumper interface to fit your testing practices. MIT license allows immediate commercial use.