<script src="https://api.example.com/data?callback=myCallback"></script>
{
"name": "John",
"age": 30
}How JSONP Works
JSONP (JSON with Padding) is a technique used to bypass cross-origin policy limitations in browsers. It works by:
- Creating a script tag with a URL that includes a callback parameter
- The server wraps the JSON response in the callback function
- The browser executes the script, calling the callback with the data
What is JSONP?
JSONP (JSON with Padding) is a technique used to request data from a server in a different domain, bypassing the same-origin policy limitations of standard AJAX requests. It works by injecting a script tag to load data wrapped in a callback function. While largely replaced by CORS, JSONP is still used for legacy APIs and cross-domain data fetching.
How to Use JSONP Tester
- Enter URL - Paste the JSONP endpoint URL
- Set callback name - Specify the callback function name (usually provided by the API)
- Send request - Click the button to execute the JSONP request
- View response - See the returned data in a formatted view
JSONP Tester Features
- Cross-domain testing - Test JSONP endpoints from any domain
- Custom callback - Specify any callback function name
- Response formatting - Pretty-print JSON responses
- Error handling - Detect and display request errors
- Request history - Keep track of recent requests
- Query parameter support - Add custom parameters to requests
Frequently Asked Questions
What is the difference between JSON and JSONP?
JSON is a data format. JSONP is a technique for loading JSON data across domains by wrapping it in a function call. JSONP responses are executed as JavaScript rather than parsed as data, which bypasses the same-origin policy restrictions of XMLHttpRequest.
Is JSONP still used today?
JSONP is largely deprecated in favor of CORS (Cross-Origin Resource Sharing), which is a more secure and flexible standard. However, some legacy APIs and older systems still use JSONP, which is why this testing tool remains useful.
Why are JSONP requests considered less secure?
JSONP executes the response as JavaScript, which means malicious code could be executed if the API provider is compromised. CORS is preferred because it allows fine-grained control over which domains can access resources and doesn't execute responses as code.