I have a JSON from web server that looks like this:
{"timestamp":1642069251.6908009,"station_id":"ORBB","channel":5,"freq":131.725,"level":-28.1,"error":0,"mode":"2","label":"Q0","block_id":"8","ack":false,"tail":"A6-ANR","flight":"G90369","msgno":"S10A"}
{"timestamp":1642069257.00876,"station_id":"ORBB","channel":5,"freq":131.725,"level":-41.3,"error":0,"mode":"2","label":"Q0","block_id":"7","ack":false,"tail":"PH-HXO","flight":"HV6905","msgno":"S28A"}
{"timestamp":1642069259.057013,"station_id":"ORBB","channel":5,"freq":131.725,"level":-24.9,"error":0,"mode":"D","label":"Q0","block_id":"9","ack":false,"tail":"A6-ANR","flight":"G90369","msgno":"S11A"}
l have followed this answer but l have nothing to show in console.
l can't edit the data JSON above to deliver a valid JSON because it's coming from a data server using Ajax.
$(document).ready(() => {
$.ajax('acarsdec.json', {
type: 'GET',
//dataType: "text",
timeout: 10000,
cache: false,
}).done(function (data, textStatus, jqXHR) {
const dataasfile = `data:text/plain;base64,${btoa(data)}`;
fetch(dataasfile).then(res => res.text()).then(text => {
let jsonstr = `[${text.split('\n').join(',')}]`;
let json = JSON.parse(jsonstr);
console.log(json);
});
})
})
dataType: "json"- that tells jQuery to parse the response as JSON automatically, but that will of course fail when it is not valid JSON.\n, you should be sure that none of the values can ever contain that kind of line break. Otherwise, this will fail or cause faulty data.)dataType: "json". Perhaps removing it makes jQuery guess wrong and it has to be explicitly set to"text".[1, 2, 3, ]which will be invalid.