Skip to content

json-extract

by official

Data

Extract structured data as validated JSON

data json extraction
# json-extract

Extract structured data as validated JSON

## Installation

This is a CmdForge tool. Once installed via `cmdforge install json-extract`, it can be used as a standard CLI command.

## Usage

```bash
# Extract data from text input
echo "John Doe, age 30, works at Acme Corp" | json-extract

# Extract specific fields
echo "Product: Widget, Price: $29.99, Stock: 150 units" | json-extract --fields "product_name,price,stock_quantity"

# Process a file
cat customer_data.txt | json-extract --fields "name,email,phone"

# Chain with other commands
curl https://api.example.com/raw | json-extract --fields "id,title,created_at"
```

## Arguments

| Flag | Default | Description |
|------|---------|-------------|
| `--fields` | any relevant fields | Specify which fields to extract from the input |

## How It Works

This tool uses a two-step pipeline:

1. **AI Extraction** (`step_1`): Uses the `opencode-deepseek` provider to analyze the input text and extract structured data based on the specified fields, generating raw JSON output.

2. **Validation** (`step_2`): Executes Python code to validate and clean the extracted JSON, ensuring the output is properly formatted and valid.

The final output is validated JSON that can be piped to other tools like `jq` or processed programmatically.

## Dependencies

None

No reviews yet.

Issues

No issues reported for this tool.