Reputation: 1610
I am trying to see a response to my url in Firefox JSON viewer, but it is always shown as a plain text. I have option devtools.jsonview.enabled
set to true
. I send a request with a header Accept: application/json
and get the response with the 'correct' content-type: application/json
. Unfortunately, it does't work with my url.
However, Firefox JSON viewer works pretty well with another url. What is it wrong with this one?
Upvotes: 2
Views: 3766
Reputation: 11
I had a similar issue. For me, it was simply that I had a valid JSON string but not a JSON object. Simply using the json.loads(data) function in my Python code did the trick for me. There should be a similar library for whatever language you’re using.
Upvotes: 1
Reputation: 612
You can use this userscript:
// ==UserScript==
// @name Force JSON Viewer for Specific URLs
// @namespace whatever
// @version 1.0
// @description Force JSON rendering for specific URLs in Firefox
// @author YourName
// @match https://auction-sandbox.ea.openprocurement.org/database/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Get the current URL
const url = window.location.href;
// Fetch the content, force JSON rendering
fetch(url)
.then(response => response.json())
.then(json => {
const jsonString = JSON.stringify(json, null, 2);
const blob = new Blob([jsonString], { type: 'application/json' });
const objectURL = URL.createObjectURL(blob);
window.location.href = objectURL;
})
.catch(error => console.error('Error fetching or parsing JSON:', error));
})();
it's permeant solution IMHO.
Upvotes: 0
Reputation: 1
I too have this issue and don't have access to change the server.
If you are just trying to view your JSON, like me, try Postman or another browser. My results below.
Firefox developers edition: JSON values as string.
Chrome and Edge: XML.
IE: Downloads JSON
Upvotes: 0
Reputation: 13087
After some investigations following your example link, and as you said, the json is valid and well formated.
But the server does not send the application/json
header correctly.
If you can't modify the server, you can still proxy it with the correct header from another server, like this:
Example in php:
<?php
header('Content-Type: application/json');
$data = file_get_contents("https://auction-sandbox.ea.openprocurement.org/database/11111111111111111111111111110149");
echo $data;
Output:
Upvotes: 3