Skip to content

Latest commit

 

History

History
75 lines (52 loc) · 1.5 KB

File metadata and controls

75 lines (52 loc) · 1.5 KB

Rust Debug Format to JSON Converter

A simple web tool that converts Rust's Debug output to JSON, making it easier to work with Rust data structures in JSON format.

URL: https://jimmygchen.github.io/rust-debug-to-json

Usage

While logging complex structures with Debug output is typically avoided due to clutter, it can be useful during testing and debugging. For specific tasks, like checking list lengths or finding elements in large nested structs, it may be useful to convert the data to a common parsable format like JSON for ease of analysis.

Example Conversions

Enum with Struct Data

Input:

The enum name is not part of the default Debug output, e.g. Deneb is the enum variant name here. Therefore it's treated similarly to a struct.

Deneb(BeaconBlockHeader { field: 123 })

Converted JSON:

{
  "type": "Deneb",
  "values": [
    {
      "type": "BeaconBlockHeader",
      "field": 123
    }
  ]
}

Option

Input:

MyStruct { optional_field: Some("present") }

Converted JSON:

{
  "type": "MyStruct",
  "optional_field": "present"  // or `null` for `None`
}

Struct with Positional Fields

Input:

Slot(13024)

Converted JSON:

{
  "type": "Slot",
  "values": [13024]
}

Known issues

This is a naive implementation mostly generated by AI. It works for basic structures, but there are some known issues:

  • It does not currently parse nested complex types correctly.
  • PhantomData is not currently handled.