Introduction
editMeziantou.Framework.HumanReadableSerializer writes any .NET object as readable, indented text, in a YAML-like format: one Name: value line per property, nested objects indented below their name, and one - item line per item of a collection. Getting started shows an example.
It is a one-way serializer: there is no deserializer. The text is made for people and for comparisons, so it is the same on every machine: numbers and dates are written with the invariant culture, and lines are separated by \n on every platform.
When to use it
- Snapshot tests.
Meziantou.Framework.SnapshotTestingandMeziantou.Framework.InlineSnapshotTestinguse it to write the value under test. See Snapshot testing. - Logs and diagnostics, to dump an object, an exception or an HTTP response in a form that is easy to read.
- Diffs, to compare two objects line by line.
What you can do with it
- Serialize any object: anonymous types, records, collections, dictionaries, enums, dates, JSON and XML documents, HTTP messages, and many .NET types. See Getting started and Output format.
- Choose, rename and order the members with attributes or options, including on types you do not own. See Members.
- Write a type your way with a converter. See Converters.
- Format JSON, XML, HTML and form values embedded in the object. See JSON, XML and HTML values.
- Write HTTP requests and responses with their headers and content. See HTTP messages.
Packages and namespaces
| Package | Content |
|---|---|
Meziantou.Framework.HumanReadableSerializer | The serializer, its options and attributes, and the JSON, XML and URL-encoded form formatters |
Meziantou.Framework.HumanReadableSerializer.Html | A formatter that normalizes HTML values |
The serializer, its options, the attributes and the converter base classes are in the Meziantou.Framework.HumanReadable namespace. The formatters are in Meziantou.Framework.HumanReadable.ValueFormatters, and the HTTP options in Meziantou.Framework.HumanReadable.Converters.