All TalkersCode Topics

Follow TalkersCode On Social Media

How To Get JSON Data From URL In HTML

Last Updated : Feb 10, 2023

How To Get JSON Data From URL In HTML

In this article we will show you the solution of how to get JSON data from URL in HTML, let us understand JSON first. The JSON stands for JavaScript Object Notation.

It is a lightweight data-exchanging format. It is used basically with API. JSON is language-independent and supports all kinds of frameworks and languages.

In this tutorial, we will get JSON data from the URL using jQuery.

Step By Step Guide On How To Get JSON Data From URL In HTML :-

Let us see an example on get JSON data from a URL in HTML. Let us see the code first.

<!DOCTYPE html>
<html lang = " en " >
    <meta charset = " UTF - 8" >
    <meta http-equiv = " X-UA-Compatible " content = " IE=edge " >
    <meta name = " viewport " content = " width = device-width , initial-scale = 1.0 " >
    <title>how to get JSON data from URL in HTML</title>
    <script src = " ">
        h1 {
         font-size : larger ;
         font-weight : bolder ;
         color : lightgreen ;
    <h1> TALKERSCODE </h1>
    <p> how to get JSON data from URL in HTML </p>
        var theURL = ' '
                $.getJSON ( theURL , function ( data ) {
                console.log ( data )
                for( i = 0 ; i<data.length ; i = i + 1 ){
                    console.log ( data [ i ].name )
        } )
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now the <head> tag is used to contain information about the web page, create a <script> tag with a URL that is used to access the library of jQuery. In this tag, a <title> tag is used which helps us to specify a webpage title.
  4. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  5. Thirdly, the <body> tag is used to define the webpage body. All the contents to show on the website are written here.
  6. <h1> tag used to add heading here.
  7. Create a <script> tag to add the JavaScript code to get JSON data from URL in HTML.
  8. We create a variable “ theURL “ using the var function.
  9. Into that variable “ theURL “ , we placed a URL containing the JSON data we are going to use.
  10. Using $.getJSON () to put the information into theURL to a function called function(data). The $ sign here used to access jQuery.
  11. Here , using console.log() to display the data consist in the URL.
  12. Also we can display particular data like name, email, etc. in it. Here we used a for loop to display all the Names in the JSON data.

Conclusion :-

At last here in conclusion, here we can say that with the help of this article we are able to know how to get JSON data from URLs in HTML.

I hope this article on how to get JSON data from URL in HTML helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials