Skip to main content
Prowl.Echo ships four interop formats — JSON, BSON, YAML, and XML — that let you move data between EchoObject trees and the wider ecosystem of web services, databases, config tooling, and legacy systems. All four are implemented from scratch with no external dependencies, and all four implement IFileFormat, so the full extension method API (WriteToString, ReadFromString, WriteToBytes, ReadFromBytes, WriteToFile, ReadFromFile) is available on every one of them.
The interop formats do not preserve every EchoType distinction. JSON, BSON, and YAML coalesce small integer types to int or double on read-back. XML preserves all types when reading Echo-produced output (via type attributes), but infers types when reading generic XML. If you need a lossless round-trip, use Echo binary or Echo text.

JSON

JsonFileFormat writes clean, standard JSON and reads both Echo-produced JSON and arbitrary JSON documents from external sources. It has no external dependencies and handles all EchoType values, encoding ByteArray as a Base64 string and special floating-point values (NaN, Infinity) as quoted strings.

Writing JSON

Compact JSON output

Access the singleton to disable indentation:

Reading JSON

EchoObject.ReadFromJson accepts any valid JSON — not just Echo-produced output — making it suitable for consuming external API responses:

Using IFileFormat extension methods

When reading generic JSON, numbers without a decimal point are parsed as int, long, or ulong (in that order of preference). Numbers with a decimal point or exponent are parsed as double. The original EchoType.Byte, EchoType.Short, and EchoType.Float distinctions are not recoverable from standard JSON.

BSON

BsonFileFormat implements the BSON specification without any external dependencies. BSON is the native wire format for MongoDB and is well supported by drivers across many languages. The format produces a byte[] and reads from a byte[], making it a natural fit for binary-oriented pipelines.

Writing BSON

Reading BSON

Using IFileFormat extension methods

Type mapping notes

BSON has a smaller set of numeric types than EchoType. The mapping applied during write is:
BSON requires a document at the top level. If you write an EchoObject that is not a Compound, it is automatically wrapped in a single-key document during write and unwrapped on read.

YAML

YamlFileFormat produces clean, indented YAML and reads both Echo-produced YAML and generic YAML documents. It supports mappings, sequences, scalars (strings, numbers, booleans, null), inline flow-style notation, and the !!binary tag for ByteArray values.

Writing YAML

Reading YAML

EchoObject.ReadFromYaml accepts any valid YAML, including documents you did not produce with Prowl.Echo:

Using IFileFormat extension methods

Type mapping notes

YAML scalars are parsed in this order: null keywords → boolean keywords → int → long → double → plain string. YAML special float values (.nan, .inf, -.inf) map to EchoType.Double. The !!binary tag maps to EchoType.ByteArray via Base64 decoding.

XML

XmlFileFormat produces standard XML 1.0 with type attributes that carry the full EchoType name. When you read Echo-produced XML back, all type information is restored exactly. It also reads generic XML that has no type attributes, inferring types by parsing the text content — useful for importing data from external XML sources.

Writing XML

The output includes an XML declaration and type attributes on every element:

Reading XML

EchoObject.ReadFromXml accepts both Echo-produced XML (with type attributes) and generic XML from external systems:

Using IFileFormat extension methods

XML element name sanitization

XML element names must start with a letter or underscore and may only contain letters, digits, _, -, and .. If a compound key does not satisfy these rules, XmlFileFormat sanitizes the element name and stores the original key in a key attribute so it is recovered faithfully on read:

Importing external documents

All four interop format readers can parse documents they did not produce. This makes it straightforward to pull data from external APIs or configuration systems into an EchoObject for processing with Echo’s serialization pipeline.
When reading generic JSON, YAML, or untyped XML, the EchoObject tree uses the broadest compatible type (e.g., int instead of byte, double instead of float). If your deserialization target type uses narrower types, the Serializer will coerce them automatically during Deserialize.