Postman to cURL
Convert Postman request JSON exports to cURL commands.
About this tool
Postman is one of the most popular API testing platforms, allowing developers to organize, document, and test HTTP requests with ease. However, sometimes you need to convert those requests into cURL commands—whether for sharing with team members, running in scripts, or embedding in documentation. This tool instantly transforms Postman JSON exports into executable cURL commands, eliminating the need for manual rewriting.
To use this converter, export your Postman request or collection as JSON, paste the JSON into the input field, and click "Convert." The tool automatically parses headers, request body, query parameters, and other settings, outputting ready-to-use cURL commands. This is especially useful for DevOps engineers, backend developers, and QA teams who need to quickly move API requests from Postman to the command line or CI/CD pipelines.
Frequently Asked Questions
Code Implementation
import json
def postman_to_curl(postman_json: str, pretty: bool = False) -> str:
data = json.loads(postman_json)
# Handle collection format
if 'item' in data:
results = []
for item in data['item']:
req = item.get('request', {})
results.append(build_curl(req, pretty))
return '\n\n'.join(results)
# Handle single request
req = data.get('request', data)
return build_curl(req, pretty)
def build_curl(req: dict, pretty: bool) -> str:
method = req.get('method', 'GET').upper()
url_obj = req.get('url', {})
url = url_obj if isinstance(url_obj, str) else url_obj.get('raw', '')
parts = [f'curl -X {method}']
for header in req.get('header', []):
val = f"{header['key']}: {header['value']}"
parts.append(f'-H "{val}"')
body = req.get('body', {})
if body.get('mode') == 'raw' and body.get('raw'):
escaped = body['raw'].replace('"', '\\"')
parts.append(f'-d "{escaped}"')
parts.append(f'"{url}"')
sep = ' \\\n ' if pretty else ' '
return sep.join(parts)
# Example
collection = json.dumps({
"method": "POST",
"url": {"raw": "https://api.example.com/data"},
"header": [{"key": "Content-Type", "value": "application/json"}],
"body": {"mode": "raw", "raw": '{"key":"value"}'}
})
print(postman_to_curl(collection, pretty=True))
Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.