Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

pixincreate/zParse

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zParse

Introduction

zParse is a high-performance Rust library and toolchain for parsing and converting JSON, CSV, TOML, YAML, and XML. It ships as a library, a CLI, and an HTTP API so you can integrate it in other Rust projects or expose it to a frontend.

Features

  • Native parsers for JSON, CSV, TOML (with native datetime types), YAML 1.2, and XML
  • Streaming/event-based parsing with depth and size limits
  • Format conversion between all supported formats
  • CLI for conversion with stdin/stdout support
  • Axum API for programmatic access

Usage

Library

use zparse::{from_csv_str, from_csv_str_with_delimiter, from_str, from_toml_str, from_yaml_str, from_xml_str};

let json_value = from_str(r#"{"name": "zparse"}"#)?;
let toml_value = from_toml_str("name = \"zparse\"\n")?;
let yaml_value = from_yaml_str("name: zparse\n")?;
let xml_doc = from_xml_str("<root><name>zparse</name></root>")?;
let csv_value = from_csv_str("name,age\nzparse,2\n")?;

// Custom CSV delimiter (semicolon, tab, pipe, etc.)
let tsv_value = from_csv_str_with_delimiter("name\tage\nzparse\t2\n", b'\t')?;
# Ok::<(), zparse::Error>(())

Conversion

use zparse::{convert, Format};

let out = convert(r#"{"name":"zparse"}"#, Format::Json, Format::Toml)?;
let csv_out = convert(r#"[{"name":"zparse","age":2}]"#, Format::Json, Format::Csv)?;
# Ok::<(), zparse::Error>(())

CLI

Top-level flags (--parse / --convert) mirror the subcommands and still accept --from / --to when you want to be explicit. Root-level flags cannot be combined with subcommands. By default, successful commands print ok. Use --print-output to write the input/converted content instead.

JSONC notes:

  • jsonc is supported as an input format (--from jsonc or .jsonc extension).
  • Output formats remain json, toml, yaml, or xml (no --to jsonc).
  • jsonc -> json outputs strict JSON (comments and trailing commas are removed).
# Auto-detect format from file extension and validate
zparse --parse input.json

# Explicitly set the input format while using top-level flags
zparse --parse input.json --from json

# Auto-detect format from file extension and echo on success
zparse --parse input.json --print-output

# Validate JSON input and print "ok" on success
zparse parse --from json input.json

# Validate TOML input and print "ok" on success
zparse parse --from toml input.toml

# Validate JSON and echo the original content on success
zparse parse --from json --print-output input.json

# Convert JSON to TOML and print "ok" on success
zparse convert --from json --to toml input.json

# Convert CSV to JSON
zparse convert --from csv --to json input.csv

# Parse a TSV file (tab-separated values)
zparse parse --from csv --csv-delimiter $'\t' input.tsv

# Convert a pipe-delimited CSV to JSON
zparse convert --from csv --to json --csv-delimiter '|' input.csv

# Convert TOML to YAML with format inference for the input
zparse convert --to yaml input.toml

# Auto-detect input format and convert to TOML
zparse --convert input.json --to toml

# Convert JSON to YAML and print the converted output on success
zparse convert --from json --to yaml --print-output input.json

# Convert XML from stdin to JSON and write to stdout
cat input.xml | zparse convert --from xml --to json

# Convert JSON to TOML, write output to a file, and print "ok" to stdout
zparse convert --from json --to toml --output output.toml input.json

# Convert permissive JSON (comments + trailing commas) to YAML
zparse convert --from json --to yaml --json-comments --json-trailing-commas input.json

# Convert JSONC to strict JSON (comments/trailing commas removed)
zparse convert --from jsonc --to json input.jsonc --print-output

# Convert JSONC input to CSV (comments/trailing commas are accepted and normalized)
zparse convert --from json --to csv --json-comments --json-trailing-commas input.jsonc

Quick usage rules

  • Use either a subcommand (parse/convert) or a top-level flag (--parse/--convert), not both.
  • --to is required for convert.
  • --from is optional when an input file path is provided (auto-detects by extension).
  • .jsonc files auto-enable JSON comments and trailing commas during parsing.
  • When reading from stdin, you must pass --from.

API

cargo run -p zparse-api
curl -s http://127.0.0.1:3000/api/health
curl -s -X POST http://127.0.0.1:3000/api/convert \
  -H "Content-Type: application/json" \
  -d '{"content":"{\"name\":\"zparse\"}","from":"json","to":"toml"}'

WASM (Browser / Node)

Build the WASM package:

wasm-pack build --target web crates/zparse-wasm

Run WASM tests in Node:

wasm-pack test --node crates/zparse-wasm

Use from JavaScript:

import init, { convert, parse, detect_format, convert_csv } from "./pkg/zparse_wasm.js";

await init();

const toml = convert('{"name":"zparse"}', "json", "toml");
const json = parse("name = \"zparse\"", "toml");
const fmt = detect_format("data.csv"); // "csv"

// Custom CSV delimiter (e.g. tab-separated)
const tsvJson = convert_csv("name\tage\nzparse\t2", "json", "\t");

Contribution

See CONTRIBUTING.md for guidelines and workflow details.

License

This project is licensed under the GPL-3.0 License.

Changelog

See CHANGELOG.md for version history and release notes.

About

A zero-dependency JSON/TOML/YAML/XML parser and converter that handles your data like a cybernetic octopus juggling bits through a quantum circus 🦀🎪✨

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.