Skip to content

Repository files navigation

🔄 cURL to JSON Converter

License TypeScript Node.js Puppeteer

A powerful TypeScript tool to convert cURL commands to structured JSON format with Puppeteer browser automation and dynamic cookie parsing.

✨ Features

  • ✅ Input Validation: validation with detailed error messages and type safety
  • 🧪 Testing Suite: Jest test coverage with organized test structure and validation tests
  • 🔍 Smart Parsing: commands and extract headers, cookies, and request parameters with comprehensive validation
  • 🤖 Puppeteer Integration: to Puppeteer-compatible format for browser automation and session management
  • 🔄 Dynamic Cookie Extraction: HTTP requests to get live cookies from websites with automatic fallback
  • 📊 Multiple Formats: to basic request object, detailed cookies, fetch options, and Puppeteer format
  • 📝 Full TypeScript Support: definitions and JSDoc documentation for all functions
  • 🔧 Modular Architecture: parser, converter, and CLI components for easy maintenance
  • 🚀 Browser Automation: Puppeteer scripts for authenticated web scraping

📦 Installation

npm install

🚀 Usage

💻 CLI

Convert a cURL file to JSON:

npx ts-node src/cli.ts --input request.txt --output converted.json

Convert from stdin:

cat request.txt | npx ts-node src/cli.ts --stdin

🔧 Programmatic

import { CurlToJsonConverter } from './src/converter'

const converter = new CurlToJsonConverter()

// Basic conversion
const result = converter.convert(curlCommand)

// Detailed cookies (async)
const detailedCookies = await converter.convertToDetailedCookies(curlCommand)

// Puppeteer-compatible cookies (async)
const puppeteerCookies = await converter.convertToPuppeteerCookies(curlCommand)

// Complete conversion with all formats
const allResults = await converter.convertAll(curlCommand)

🤖 Puppeteer Integration

import puppeteer from 'puppeteer'
import { CurlToJsonConverter } from './src/converter'

const converter = new CurlToJsonConverter()
const puppeteerCookies = await converter.convertToPuppeteerCookies(curlCommand)

const browser = await puppeteer.launch({ headless: false })
await browser.setCookie(...puppeteerCookies)

const page = await browser.newPage()
await page.goto('https://example.com')

📋 Output Formats

Basic Request Object

{
  "url": "https://example.com/api",
  "method": "GET",
  "headers": { "authorization": "Bearer token" },
  "cookies": { "session": "abc123" },
  "compressed": true
}

Detailed Cookies

[
  {
    "name": "sessionKey",
    "value": "sk-ant-sid01-...",
    "domain": "claude.ai",
    "path": "/",
    "expires": 1756488873,
    "httpOnly": true,
    "secure": true,
    "sameSite": "Lax"
  }
]

Puppeteer Cookies

[
  {
    "name": "sessionKey",
    "value": "sk-ant-sid01-...",
    "domain": "claude.ai",
    "path": "/",
    "expires": 1756488873,
    "httpOnly": true,
    "secure": true,
    "sameSite": "Lax",
    "sameParty": false,
    "sourceScheme": "NonSecure"
  }
]

🧪 Testing

Run the complete test suite:

npm test

Run specific tests:

npm run test:watch                # Watch mode
npm run test:coverage             # Coverage report
npm run validation-test           # Validation tests
npm run puppeteer-format-test     # Puppeteer format tests

🛠️ Scripts

  • npm run convert: Run the converter
  • npm run test: Run all tests
  • npm run test:watch: Run tests in watch mode
  • npm run test:coverage: Generate coverage report
  • npm run validation-test: Test input validation
  • npm run puppeteer-format-test: Test Puppeteer cookie format
  • npm run build: Compile to JavaScript
  • npm start: Run compiled version

🔍 Validation Features

  • cURL Command Validation: Ensures proper cURL syntax and URL format
  • Input Validation: Validates string inputs and file paths
  • Error Handling: Comprehensive error messages with context
  • Type Safety: Full TypeScript type checking

🎯 Use Cases

  • Web Scraping: Convert browser requests to automated scripts
  • API Testing: Transform cURL commands to test suites
  • Session Management: Extract and reuse authentication cookies
  • Browser Automation: Inject cookies into Puppeteer for authenticated sessions
  • Request Analysis: Parse and analyze complex HTTP requests

📁 Project Structure

src/
├── parser.ts            # cURL command parsing
├── converter.ts         # Format conversion logic
├── cli.ts               # Command-line interface
├── types.ts             # TypeScript definitions
└── index.ts             # Main exports

tests/
├── parser.test.ts       # Parser unit tests
├── converter.test.ts    # Converter unit tests
├── validation.test.ts   # Validation tests
├── puppeteer.test.ts    # Puppeteer integration tests
└── simple.test.ts       # Basic test setup

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Convert cURL commands to JSON format with Puppeteer browser automation. Parse headers, extract cookies, and inject them into automated browser sessions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages