I'm looking for a way to transform JSON into a table automatically in the chorme

0

My university has a facile website, so I set up schemes to be notified in the discord (using a plugin called Distill and a webhook) every time a note changes. However, the addresses I am updating to check for changes show text in JSON. And discord webhook does not accept for some reason.

So what I'm needing is something that turns this around:

{
"Notas" : [
     {
        "id": 95825,
        "tipo": "PROVA",
        "nome": "P1"
                                        ,"valor": "9.3"
                                }
    ,     {
        "id": 95826,
        "tipo": "PROVA",
        "nome": "P2"
                                            }
    ,     {
        "id": 95827,
        "tipo": "TRABALHO",
        "nome": "T"
                                            }
    ,     {
        "id": 95821,
        "tipo": "PROVA SUBSTITUTIVA",
        "nome": "PS"
                                            }
            ],
    "MediaParcial":"1.9",
            "LimiteInferiorExame":"4.0",
"LimiteSuperiorExame":"6.0",
"MediaAprovacao":"6.0",
"Formula":"(P1*2 + P2*2 + T*6)/10",
"Quantidade":4
}

In something like this:

Thistablewasmadeusingthis: link or that link

I looked for some Tampermonkey script ... until I found some things that made JSON look better, but nothing like a table.

If anyone can give me some idea, I am very grateful because I will be able to receive the notes by discord instead of just a warning as I have done

    
asked by anonymous 10.02.2018 / 19:28

1 answer

0

I do not know if this is what you want, but just do a loop of repetition in the Object. I used jquery for this. And still bootstrap table to stylize the table.

HTML:

<table class="table table-striped">
  <tr>
    <th>ID:</th>
    <th>TIPO:</th>
    <th>NOME:</th>
  </tr>
</table>

JS:

var table = [
    {
        "id": 95825,
        "tipo": "PROVA",
        "nome": "P1"
    }
    ,     
    {
        "id": 95826,
        "tipo": "PROVA",
        "nome": "P2"
    }
    ,     
    {
        "id": 95827,
        "tipo": "TRABALHO",
        "nome": "T"
    }
    ,
    {
        "id": 95821,
        "tipo": "PROVA SUBSTITUTIVA",
        "nome": "PS"
    }
];

$.each(table, function(i, obj) {
    var tr = $('<tr></tr>');

    $.each(obj, function(key, result) {
    var td = $('<td></td>');
    td.text(result);
    tr.append(td);
  });
  $('table').append(tr);

});

Link JS FIDDLE

    
10.02.2018 / 20:54