Jump to content

Javascript parser for v3 json help

Othniel Alexandre

Recommended Posts

Anyone able to share their javascript parser for the vatsim json v3 data feed. I am in my first month of java scripting and I am complete lost with this structure. It is so nested but the biggest challenge I seem to be facing is data type conversions going from utf8 and to byte and to string and json. I have no clue which should come first or when. My latest rendition looks like this: I think I drilled into the data far enough to find the real content but it looks really funky which leads me to believe there is some type of data conversion issue.

let url = 'https://data.vatsim.net/v3/vatsim-data.json';
    let results;
    await fetch (url, {'method''get'})
    .then((httpResponse) => {httpResponse.json()
        results = httpResponse
    let decoded = utf8Decode(JSON.stringify(results))
    let rawdata = JSON.parse(decoded)
    let thedata = bin2string(rawdata.body._outBuffer.data)
the data looks like this:
"{\"general\":{\"version\":3,\"reload\":1,\"update\":\"20210328201544\",\"update_timestamp\":\"2021-03-28T20:15:44.9810021Z\",\"connected_clients\":1526,\"unique_users\":1465},\"pilots\":[{\"cid\":1451563,\"name\":\"Marco Dubeux SBRF\",\"callsign\":\"ANZ756UUUUUUUUUUUUUUUU\u0004\u0000\u0000\u0000\u0000(\u001cº\u0004\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ified: Sun, 28 M\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000020:15:47 GMT\r\nET\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000060e3f3-11025e\"\r\u0000\u0000\u0000\u0000\u000...

I can tell that the fulfillmentValue tag has the actual data, but why it shows up the way it does is beyond me.

I know your time is valuable, but any help is much appreciated.

Link to comment
Share on other sites

I don't have a lot of experience with JS, so I'm probably missing something, but it seems to me that you are parsing the feed twice. The httpResponse.json() call parses it into an object, then you serialize it back into a JSON string, and then parse it back into an object. Why parse it twice?

Developer: vPilot, VRC, vSTARS, vERAM, VAT-Spy

Senior Controller, Boston Virtual ARTCC

Link to comment
Share on other sites

This isn't really specific to the datafeed, but here is a basic snippet of how to do it, refreshing data every 30s. Check out the MDN Docs on async/await.

Keep in mind that you **cannot** get data from the datafeed from a browser. You have to do this from your own server and then pass the data onto your clients. This is to reduce the amount of requests to the datafeed. You could use node.js to create a simple server for this. Anyway:

const fetchData = async () => {
    try {
        const response = await fetch("https://data.vatsim.net/v3/vatsim-data.json");
        return response.json();
    } catch(error) {
        console.log("Error fetching data:", error);

const updateData = () => {

    setTimeout(async () => {
        const data = await fetchData();
    }, 30000);



Developer: vatsim.net | community.vatsim.net | estvacc.org

                                                           vatsim tech logo


Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Create New...