curl to Code Converter

Paste a curl command and get the equivalent request as Python requests, JavaScript fetch, Node axios or PowerShell, with the parsed request shown alongside.

Loading tool…

Everything is parsed and generated by JavaScript in your browser. Nothing you paste is uploaded, logged or sent anywhere — which matters here, because API commands usually contain a live token.

What the curl to Code Converter does

Use this curl to code converter to paste a curl command and get the equivalent request as Python requests, JavaScript fetch, Node axios or PowerShell, with the parsed request shown alongside. Everything runs inside this page, so the work happens on your own device rather than on a server. It is most often used for turning an API doc’s curl example into working Python or JavaScript. More utilities in this area are collected on FreeToolStation.org.

How to use it

  1. Paste a curl command — from a terminal, an API doc, or your browser’s "Copy as cURL".
  2. Pick the language you want it in.
  3. Read the generated code, and check the parsed request underneath if anything looks off.
  4. Copy the code with the button above the output.

How it works

A curl command is a shell command, not a data format, and that is what makes converting one by hand error-prone. The things people paste use every shell feature at once: JSON wrapped in single quotes so its own double quotes survive, backslash-newline continuations from a documentation snippet, caret continuations from Windows cmd, a dozen repeated -H flags, and a URL that might sit before the flags, after them, or behind --url. This tool tokenises the command the way a shell would — honouring single quotes as literal, double quotes with escapes, and bare backslash escapes — rather than splitting on spaces and hoping.

Three flags change what the request means, and all three are routinely translated wrongly. The first is -G: it moves the --data payload into the query string and sends no body at all, so a GET with -d is not a POST. The second is repeated --data, which curl joins with an ampersand into a single body rather than sending the last one. The third is a Content-Type header that disagrees with the body — if you declare text/plain and pass a JSON object, the server gets text, and a converter that guesses from the body shape instead of the header will generate the wrong call.

The generated code is what someone would actually write, not a mechanical transliteration. Python gets a real dict passed to requests’ json= parameter rather than a hand-serialised string, and the Content-Type header is dropped because requests sets it itself — leaving a hand-set copy in is how you end up declaring a type that no longer matches the body. Basic auth becomes the auth= tuple instead of a base64 header you have to build. JavaScript gets URLSearchParams for query strings and FormData for multipart, and the Content-Type is deliberately omitted there because only FormData knows the boundary it generated.

Two details in the output are deliberate additions rather than translations. Python gets an explicit timeout, because requests has none by default: a request to an unresponsive host hangs until the process is killed, and it is the single commonest bug in generated client code. The fetch output checks response.ok before parsing, because fetch does not reject on a 404 or a 500 — it resolves normally with the error status, so code that goes straight to .json() fails with a confusing parse error instead of the HTTP error that actually happened.

Some things cannot be translated and are reported rather than guessed. A body read from a file with -d @payload.json is not in the command, so the generated code opens that file instead. A -F field pointing at a file becomes a commented line in the browser output, since a web page cannot read an arbitrary path. Unrecognised options are listed rather than silently dropped, so you can see what was ignored. Nothing here sends a request: the command is parsed and printed, never executed.

When to use it

  • Turning an API doc’s curl example into working Python or JavaScript.
  • Converting a browser "Copy as cURL" into code you can put in a script.
  • Checking what a long curl command actually does, flag by flag.
  • Porting a request between languages without re-reading two sets of docs.
  • Spotting a -G or a repeated --data that you would have translated wrongly.

Common mistakes to avoid

  • Treating -G as a POST. It moves the data into the query string and sends no body.
  • Keeping only the last --data when there are several. curl joins them with an ampersand.
  • Setting Content-Type by hand alongside a JSON body in requests, so the header and the body can disagree.
  • Setting Content-Type on a FormData request, which breaks the multipart boundary.
  • Going straight to response.json() after fetch. A 500 resolves normally, so the status has to be checked.
  • Leaving out a timeout in Python, where requests waits indefinitely by default.

Frequently asked questions

Does this send the request?

No. The command is parsed and the code is printed; nothing is executed and no network request is made. Everything happens in your browser, so a command containing a live API token never leaves your machine.

Which languages are supported?

Python with requests, browser JavaScript with fetch, Node.js with axios, and PowerShell with Invoke-RestMethod. The picker switches between them and the parsed request stays the same.

Will it handle a command copied from Chrome DevTools?

Yes — that is one of the shapes it is built for. DevTools emits double-quoted arguments with backslash-escaped JSON inside, often across many lines, and the tokeniser handles both that and the single-quoted style that Unix shells produce.

What happens to -d @file.json?

The file contents are not in the command, so they cannot be inlined. The generated code opens that file instead, and a note says so. The same applies to a -F field pointing at a file path.

Why does the Python output add a timeout I did not ask for?

Because requests has no default timeout at all, and a request to a host that accepts the connection and then goes quiet will hang forever. Thirty seconds is a safe default; if the original command had -m, that value is used instead.

Why is the Content-Type header missing from the output?

Only where the library sets it correctly itself. requests sets it from the json= argument, and FormData sets it along with the multipart boundary it generates. Keeping a hand-written copy in those cases causes a mismatch rather than preventing one. Any other Content-Type is passed through unchanged.

Related tools

See all developer tools →