CIRCUITO
CARIOCA TI · DOCUMENTATION
♙
Developer tool

JSON & YAML Formatter

Validate and pretty-print JSON, convert JSON to YAML, and convert YAML to JSON when the server has the PHP YAML extension.

JSONYAMLPretty PrintValidationRFC 8259YAML 1.2

JSON and YAML processor

JSON support is native to PHP. Full YAML parsing is enabled only when the server provides the PECL yaml extension backed by LibYAML.

Maximum input: 1 MiB.
JSON · RFC 8259

JSON is a data interchange format, not just “JavaScript object syntax”

RFC 8259 defines a JSON text as a serialized value. A top-level JSON document can therefore be an object, array, string, number, true, false or null. JSON exchanged between systems outside a closed ecosystem must use UTF-8 for interoperability.

PRETTY PRINT

Formatting changes presentation, not the intended data model

Pretty-printing adds indentation and line breaks to make JSON easier to inspect. This page parses the document and serializes it again, so it should not be used when byte-for-byte preservation, original whitespace or lexical number formatting must be retained.

DUPLICATE NAMES

Valid JSON can still be problematic for interoperability

RFC 8259 says object member names should be unique. When duplicate names occur, parsers differ: some keep only the last value, some report an error and others preserve all pairs. A parse-and-reformat tool can therefore lose information from JSON objects with duplicate member names even when the input is accepted syntactically.

LARGE NUMBERS

JSON number syntax does not guarantee arbitrary numeric precision

RFC 8259 allows implementations to impose numeric range and precision limits and notes that IEEE 754 binary64 is a common interoperability baseline. This page asks PHP to preserve integers that exceed its native integer range as strings during decoding, reducing accidental integer truncation, but conversions between JSON and YAML can still change type semantics for extreme numeric values.

YAML 1.2.2

YAML is richer than JSON

YAML 1.2 supports mappings, sequences and scalars, but its representation model also includes features such as tags, anchors and aliases. YAML 1.2 defines a JSON schema and is designed with JSON compatibility in mind, yet a general YAML document can express representation details that do not map one-to-one to plain JSON.

ANCHORS · ALIASES · TAGS

Converting YAML to JSON can be lossy even when parsing succeeds

Anchors identify nodes for later aliases, and tags carry type or application metadata. After YAML is composed into native PHP values and then serialized as JSON, presentation details, anchor names and YAML-specific tagging semantics may no longer exist. Use this converter for data transformation, not as a round-trip YAML editor.

SERVER CAPABILITY

Why YAML → JSON may be unavailable on this installation

PHP core provides JSON functions, while the YAML functions used here come from the PECL yaml extension and are handled by LibYAML. When that extension is absent, this page refuses full YAML parsing instead of implementing a fragile subset parser that could silently reinterpret configuration data.

UNTRUSTED YAML

YAML parsing needs a server-side security decision

The PHP yaml_parse() manual warns that processing untrusted input is dangerous when unserialize support for !php/object nodes is enabled through yaml.decode_php. Because this is a public web utility, the page refuses YAML parsing when that setting is enabled instead of accepting the risk.

FALLBACK MODE

The built-in fallback is intentionally one-way and conservative

Without PECL yaml, JSON → YAML still works for the JSON data model. The fallback quotes all strings and mapping keys, preserves booleans and null explicitly and emits nested arrays and mappings. It does not claim support for YAML anchors, aliases, tags, directives, block scalars, comments or arbitrary YAML input.

JSON_VALIDATE · PHP 8.3+

Validation-only workloads can avoid building the decoded structure

PHP 8.3 introduced json_validate(), which can validate syntax with less memory when the parsed value is not needed. This page also reports structural metadata after validation, so it decodes once instead of calling json_validate() and then decoding the same input a second time.

FAQ

JSON and YAML frequently asked questions

What does this JSON formatter do?+

It parses JSON and serializes it again with indentation, readable line breaks, Unicode characters and slashes left unescaped where PHP can safely do so.

Can a JSON document contain only a string, number or null?+

Yes. RFC 8259 defines a JSON text as a serialized value, so the root does not have to be an object or array.

Does JSON require UTF-8?+

RFC 8259 requires UTF-8 for JSON exchanged between systems that are not part of a closed ecosystem. PHP JSON decoding also expects UTF-8 strings.

Are duplicate JSON object names valid?+

RFC 8259 says object member names should be unique. Parsers behave differently when duplicates occur, so duplicate names are an interoperability risk and can be lost during parse-and-reformat operations.

Does formatting preserve the original JSON byte for byte?+

No. Parsing and serializing changes whitespace and can normalize representation details. It should not be used when exact source preservation is required.

Can JSON contain comments?+

Standard JSON defined by RFC 8259 has no comment syntax. Configuration formats that accept comments are using an extension or a different format.

Can JSON use trailing commas?+

No. A trailing comma is not part of the RFC 8259 JSON grammar.

Why can very large JSON numbers be problematic?+

JSON defines number syntax, but implementations can impose range and precision limits. This page asks PHP to preserve integers outside its native integer range as strings during decoding.

Does PHP need an extension for JSON?+

Modern PHP provides JSON functionality as part of its standard runtime. This page uses json_decode() and json_encode() with exceptions for reliable error handling.

What is json_validate()?+

PHP 8.3 introduced json_validate() for syntax validation without building the decoded value. This page needs structural metadata too, so it decodes once rather than parsing twice.

Why can YAML → JSON be unavailable?+

The YAML parser used here comes from the PECL yaml extension backed by LibYAML. If that extension is not installed, the page does not attempt full YAML parsing.

Does JSON → YAML work without the YAML extension?+

Yes, for JSON data. A conservative fallback emits mappings, sequences and JSON-compatible scalar values, but it is not a general YAML emitter.

Does the fallback support anchors and aliases?+

No. The fallback only serializes the JSON data model and does not implement YAML anchors, aliases, tags, directives or comments.

What are YAML anchors and aliases?+

An anchor labels a node and an alias can refer to an anchored node later in the YAML serialization. These relationships do not map perfectly to ordinary JSON.

Are YAML and JSON equivalent formats?+

No. YAML 1.2 has strong JSON compatibility, but YAML has additional representation features and conversion can lose YAML-specific information.

Can YAML comments survive conversion to JSON?+

Not with this data conversion. Comments are presentation-level information and are not represented by ordinary JSON values.

Why can YAML → JSON be lossy?+

YAML tags, aliases, anchor names, scalar styles, comments and other source-level details can disappear when YAML is composed into native values and then serialized as JSON.

Is parsing public YAML input safe?+

It depends on the parser configuration. The PHP manual specifically warns about untrusted yaml_parse() input when !php/object unserialization is enabled through yaml.decode_php. This page refuses parsing in that configuration.

Does this page support multiple YAML documents in one stream?+

No. The converter intentionally accepts one YAML document at a time so the JSON output has one unambiguous root value.

Which standards are relevant here?+

RFC 8259 defines JSON. YAML 1.2.2 is the current YAML specification revision referenced by this page; PHP YAML parsing and emission depend on the installed PECL yaml/LibYAML implementation.