Home Text Tools Math & Numbers Developer Tools Date & Time Image Tools Blog
JSONP to JSON Converter

Strip the JSONP Callback and Reuse Old API Data as Plain JSON

An old API returns callback({...}) instead of JSON. Learn what JSONP is, how to unwrap it, and how to use the data in modern code.

You find an older API that answers with something like callback({"name":"Lena"}); and your JSON parser throws an error. That response is JSONP, a workaround from before browsers had a standard way to make cross-site requests. The JSONP to JSON Converter removes the wrapper so you can work with the data directly.

JSONP to JSON Converter FREE online toolRuns in your browser. No sign-up, nothing to install. Open the tool

What JSONP is

JSONP wraps JSON data in a function call. A page would add a script tag pointing to the API with a callback name, and the server replied with JavaScript that calls that function with the data as its argument. This sidestepped the browser rule that blocked ordinary cross-origin requests, which is why it was popular around the early 2010s.

Today the standard approach is CORS, where the server sends headers that allow the request, and the response is plain JSON. Some older services never moved over, so JSONP responses still turn up.

Unwrap a response

  1. Copy the full response text, including the function name and the parentheses.
  2. Paste it into the JSONP to JSON Converter.
  3. The tool removes the callback name, the opening and closing parentheses, and a trailing semicolon.
  4. Check that the result begins with a curly brace or square bracket.
  5. Copy the clean JSON into your code, a validator, or a file.

Check that the JSON is valid

Stripping the wrapper is only the first step. JSONP is actually JavaScript, so the content inside may not be strict JSON. Single-quoted strings, unquoted keys, and trailing commas are valid in JavaScript objects but are rejected by JSON parsers. If parsing fails after unwrapping, look for those details and fix them.

Running the cleaned text through a JSON validator tells you exactly which line causes trouble.

Use the data safely

  • Do not execute a JSONP response you do not trust. It is code, and running it gives the server full access to your page.
  • Parse the unwrapped text as data instead of evaluating it.
  • Check whether the service still supports a plain JSON format by dropping the callback parameter or adding a format option.
  • Look at the license or terms before storing the data.
  • Cache results sensibly so you do not hammer an old server.

When you work in code

If you are writing a script rather than pasting by hand, you can strip the wrapper with a regular expression that captures everything between the first opening parenthesis and the last closing one, then parse that part. In Node.js or a modern browser you can request the endpoint without a callback and see whether it returns clean JSON already.

For one-off jobs, a converter is faster than writing and testing a pattern.

A before and after example

A response like handleData({"id":7,"tags":["a","b"]}); becomes {"id":7,"tags":["a","b"]} once the function name, parentheses, and semicolon are removed. Paste that into a validator and a JSON viewer, and you can read the fields easily.

Tidy the output

Once you have valid JSON, formatting it with indentation makes it readable. From there you can explore the keys, pick the fields you need, or convert it to another format. If you plan to use the data repeatedly, save a sample response so you can develop offline and avoid depending on an aging endpoint.

Try the free JSONP to JSON Converter
Runs in your browser. No sign-up, nothing to install.

Comments (0)

No comments yet. Be the first to share a thought.