0

I have coded an url-shortener using Node.JS and saving in json-data. Now I'm coding an Web-Dashboard for my Team to manage the urls. I like to use forEach, because I can easily use it to add code to my html site for each entry. My problem: I have json data just like this:


    {
      "support": {
        "url": "https://this-is-the-url.end",
        "author": "Name of the Author"
      },
      "invite": {

      "url": "https://an-other-url.end",
      "author": "Name of the Author"
    },
    .
    .
    .
    }

and I dont know how to split it so I can use

Object.forEach(json => {
var author = json.author
var url = json.url

*add code to html code*

})

I already searched on Stackoverflow but i could not find something. Can someone help me?

Dr. Tigga
  • 7
  • 4

2 Answers2

0

Like this?

Object.keys(bigJson).forEach(key => {
  const json = bigJson[key];
  const author = json.author;
});

(Note that bigJson and json are not actual JSON strings, they're objects, but I wanted to keep OP's naming to avoid confusion at this point.)

Stratubas
  • 2,939
  • 1
  • 13
  • 18
0

It might be like this:

import json from '/some/path/to/urls.json';

Object.entries(([key, value]) => {
  doSthWith(key); // 'support', 'invite';
  doSthElseWith(value.url, value.author);
})
Silo QIAN
  • 60
  • 8