S
S
sobot2020-07-04 13:18:04
JavaScript
sobot, 2020-07-04 13:18:04

How to parse JSON file using JS?

Good afternoon!

I have a main.json file, how do I read it so I can use JSON.parse in JavaScript?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Salavat Salakhutdinov, 2020-07-04
@sobot

fetch('https://example.com/main.json')
   .then(response => response.json())
   .then(json => {
       // console.log(json);
   })

You don't need to parse via JSON.parse, as it will already be parsed using response.json()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question