Skip to main content

to_json

Function to_json 

Source
pub fn to_json(
    file: &str,
    output: Option<&str>,
    metadata: bool,
    pretty: bool,
) -> Result<(), CliError>
Expand description

Convert a HEDL file to JSON format.

Parses a HEDL file and converts it to JSON, with options for metadata inclusion and pretty-printing.

§Arguments

  • file - Path to the HEDL file to convert
  • output - Optional output file path. If None, writes to stdout
  • metadata - If true, includes HEDL-specific metadata in the JSON output
  • pretty - If true, pretty-prints the JSON with indentation

§Returns

Returns Ok(()) on success.

§Errors

Returns Err if:

  • The file cannot be read
  • The file contains syntax errors
  • JSON conversion fails
  • Output writing fails

§Examples

use hedl_cli::commands::to_json;

// Convert to compact JSON on stdout
to_json("data.hedl", None, false, false)?;

// Convert to pretty JSON with metadata
to_json("data.hedl", Some("output.json"), true, true)?;