Using json online

Heyo!

So, I’m trying to make something like https://aws.random.cat/meow however, when using my code with a discord bot, it isn’t working.. It makes me wonder if you can host json things online directly by using the below code:

document.body.innerHTML = "<pre style=\"word-wrap: break-word; white-space: pre-wrap;\">{\"file\":\"https:\\/\\/"+domain+"\\/images\\/hug\\/"+item+"\"}</pre>";

Furthermore, my bot code is:

const { MessageEmbed } = require('discord.js');
const axios = require('axios');
const {get} = require("snekfetch");

const embed = new MessageEmbed()
        .setColor("RANDOM")
        .setTitle("thingie")
        .setDescription("Loading...")
message.channel.send(embed).then(msg => {
    get('https://example.com/kiss').then(response => {
        setTimeout(function(){ 
            embed.setDescription("")
            embed.setImage(response.body.file)
            msg.edit(embed)
        }, 1500);
    });
})

My website is working perfectly and is showing exactly as in https://aws.random.cat/meow However, it still doesn’t work. Please lmk how or why this is happening.

P.S I didn’t include the modules.export part in the bot code cuz, I thought it was extra.

P.P.S The following is my current output: This

Thanks!

4 thoughts on “Using json online”

  1. If you want to provide data in a JSON format on your endpoint then just provide the JSON part, no need to put it in an HTML. If you put your JSON inside HTML like a string, then when you do get(<your url>) you’ll get the entire HTML code with the embedded JSON, and so response.file doesn’t work.

    The reason why https://aws.random.cat/meow shows up as being embedded within HTML is because the browser detects that it is a JSON file and hence it does the embedding automatically. Here is the RAW response from that URL when you try to make the request using wget on the command line:

    $ wget https://aws.random.cat/meow --no-check-certificate
    $ cat meow
    {"file":"https:\/\/purr.objects-us-east-1.dream.io\/i\/935392_10151612620866211_62628372_n.jpg"}
    

    As you can see, there’s no HTML around it. It’s pure JSON.

    To verify that this is indeed the case, log the response you get from your url:

    get('https://example.com/kiss').then(response => {
        console.log(response.body);
    });
    

    Unrelated: anyone else appreciate the cat meow coincidence here?

    Reply

Leave a Comment