Before CORS was widely supported, browsers blocked scripts from reading data across domains, with one loophole: script tags can load code from anywhere. JSONP uses that loophole by wrapping data in a function call. If you maintain an old site that cannot use modern requests, the JSON to JSONP Converter wraps your data in a callback in seconds.
JSON to JSONP Converter FREE online toolRuns in your browser. No sign-up, nothing to install. Open the tool →How JSONP works
Plain JSON, such as {"name":"Mona"}, is not executable on its own. JSONP wraps it as showData({"name":"Mona"}); and serves it as JavaScript. The page defines a function called showData, then adds a script tag pointing to the file. When the script loads, the browser runs it and calls your function with the data.
Set it up in five steps
- Paste your JSON into the converter and enter a callback name, such as showData.
- Copy the wrapped output and save it as a .js file, or serve it with the JavaScript content type.
- In the legacy page, define function showData(data) before the script loads.
- Add a script tag with the src pointing to the file on the other domain.
- Open the page and check the browser console for errors.
Limits you should know
- Only GET-style loading works; you cannot send POST bodies this way.
- There is no useful error handling, because a failed script load tells you little.
- The callback must exist in the page's global scope.
- Data is evaluated as code, not parsed as data.
- Responses are harder to cache and debug than ordinary JSON.
Security matters
Loading JSONP means running whatever the other domain sends. If that server is compromised, or if you load from an untrusted host, the response can do anything the page can do. Only use sources you control or fully trust. If you build the server side, validate the callback parameter strictly: allow letters, digits, underscores and dots, and refuse anything else, otherwise attackers can inject script. Never serve private or user-specific data through JSONP, since any website can include your script tag and receive the data.
Prefer CORS when you can
Modern browsers support Cross-Origin Resource Sharing. With a proper Access-Control-Allow-Origin header, a page can use fetch and receive plain JSON safely, with error handling and other methods. JSONP is a compatibility tool for very old browsers or pages you cannot change. If you have the choice, use CORS, or serve the data from the same origin through a proxy.
A quick example
Suppose a legacy dashboard needs a list of branch names stored on another server. You save branches.js containing loadBranches(["Cairo","Giza"]); on that server. The dashboard page defines function loadBranches(list) to fill a drop-down, then includes the script tag. When the file loads, the function runs once with the array. If you later change the data, update only the file, and leave the dashboard code as it is. Add a version in the file name when browsers cache the old copy.
Testing the result
Check the response in the browser network panel: the type should be JavaScript and the body should begin with your callback name. If you see a syntax error, make sure the JSON is valid before wrapping, and that no stray characters, such as a trailing comment, were added. For static hosting, a plain file with the wrapped content is often enough, which keeps the setup simple.
Comments (0)
No comments yet. Be the first to share a thought.