Skip to main content

XDR-JSON

The XDR-JSON schema is defined by the stellar-xdr crate and provides a round-trippable means for converting Stellar XDR values to JSON and converting that JSON back to the identical XDR.

Converting with the schema is also exposed by the following tools and libraries.

The JSON-Schema for the XDR-JSON format can be found using the stellar xdr types schema command.

Tools

Libraries

Key Characteristics of the JSON and XDR Conversion Schema

  • Round-Trippable: The JSON format allows for converting from XDR to JSON and back to XDR without loss of information.

  • Self-Describing: The JSON format describes the internals of the type but does not identify the type that is encoded. This is similar to XDR, which also does not identify the encoded type.

  • 64-bit Integers: The JSON format includes integers up to 64-bit in size. JavaScript runtimes do not support 64-bit integers, so a custom decoder must be used, such as lossless-json.

  • Escaped ASCII Strings: The JSON format includes strings that are UTF-8 safe, escaped ASCII strings. This is because XDR strings are not UTF-8 encoded, but are instead byte streams that can contain any values. Non-ASCII characters are escaped.

backwards-incompatible

The defined schema (linked above) is not backwards compatible between a given protocol version and prior versions. The best practice is to store required ledger data in XDR format, not in JSON format.