2025-07-20 11:20:19 +02:00
2025-04-22 10:53:25 +02:00
2025-03-27 19:49:57 +01:00
2025-07-20 11:20:19 +02:00
2025-03-28 00:03:23 +01:00
2025-04-18 12:48:24 +02:00
2025-07-20 11:20:19 +02:00
2025-07-20 11:20:19 +02:00
2025-07-20 11:20:19 +02:00
2025-03-26 11:40:23 +01:00

Big Chef

A Go-based tool for modifying XML, JSON, and text documents using XPath/JSONPath/Regex expressions and Lua transformations.

Features

  • Multi-Format Processing:
    • XML (XPath)
    • JSON (JSONPath)
    • Text (Regex)
  • Node Value Modification: Update text values in XML elements, JSON properties or text matches
  • Attribute Manipulation: Modify XML attributes, JSON object keys or regex capture groups
  • Conditional Logic: Apply transformations based on document content
  • Complex Operations:
    • Mathematical calculations
    • String manipulations
    • Date conversions
    • Structural changes
    • Whole ass Lua environment
  • Error Handling: Comprehensive error detection for:
    • Invalid XML/JSON
    • Malformed XPath/JSONPath
    • Lua syntax errors

Usage Examples

1. Basic field modification

<!-- Input -->
<price>44.95</price>

<!-- Command -->
chef -xml "//price" "v=v*2" input.xml

<!-- Output -->
<price>89.9</price>

2. Supports glob patterns

chef -xml "//price" "v=v*2" data/**.xml

3. Attribute Update

<!-- Input -->
<item price="10.50"/>

<!-- Command -->
chef -xml "//item/@price" "v=v*2" input.xml

<!-- Output --> 
<item price="21"/>

3. JSONPath Transformation

// Input
{
  "products": [
    {"name": "Widget", "price": 19.99},
    {"name": "Gadget", "price": 29.99}
  ]
}

// Command
chef -json "$.products[*].price" "v=v*0.75" input.json

// Output
{
  "products": [
    {"name": "Widget", "price": 14.99},
    {"name": "Gadget", "price": 22.49}
  ]
}

4. Regex Text Replacement

Regex works slightly differently, up to 12 match groups are provided as v1..v12 and s1..s12 for numbers and strings respectively. A special shorthand "!num" is also provided that simply expands to (\d*\.?\d+).

<!-- Input -->
<description>Price: $15.00 Special Offer</description>

<!-- Command -->
chef "Price: $!num Special Offer" "v1 = v1 * 0.92" input.xml

<!-- Output -->
<description>Price: $13.80 Special Offer</description>

5. Conditional Transformation

<!-- Input -->
<item stock="5" price="10.00"/>

<!-- Command -->
chef -xml "//item" "if tonumber(v.stock) > 0 then v.price = v.price * 0.8 end" input.xml

<!-- Output -->
<item stock="5" price="8.00"/>

Installation

go build -o chef main.go
# Process XML file
./chef -xml "//price" "v=v*1.2" input.xml

# Process JSON file 
./chef -json "$.prices[*]" "v=v*0.9" input.json
Description
No description provided
Readme 1.2 MiB
v5.2.3 Latest
2025-04-22 08:53:35 +00:00
Languages
Go 99.4%
Shell 0.6%