Skip to content

jimmygchen/rust-debug-to-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages