Fetch Data from JSON File in React JS | React JSON [ UPDATED ]

Поделиться
HTML-код
  • Опубликовано: 21 фев 2022
  • How to fetch data from JSON file in react js? How to use an Array map within map in JSX React JS? This is what we will learn in this tutorial:
    - 'Display JSON Data in React app' directly.
    - Use JavaScript Array map() to display data.
    - Use Array map inside Array map.
    - Fetch records in React JS from nested objects in JSON file.
    So how do we fetch data from JSON file in react? It's very easy. I have a separate JSON file with data (array and objects) in it. File name is records.json. JSON is a clean data representation format. Anything that you write in JSON is valid JavaScript. JSON supports strings, numbers, booleans, null, arrays and objects.
    Arrays have opening and closing square brackets. Objects are stored inside curly brackets. To use data inside a JSON file, we take an opening and closing square brackets. Inside brackets, we take objects in curly braces. Object has got key, value pairs. In JSON we write keys with double quotes.
    To display this JSON data in ReactJS, we import JSON file in React component, by using any name. Period slash represent that JSON file is at same location where this App.js is in the project. To map JSON object, take curly brackets and use Array map and provide it JSON file data that was imported at the top of component. Also apply a check with &&. This is to check if we have data to map. If we have data then statement will proceed otherwise it won't execute further. It's important. Always check if data exists before displaying it. JSON records are displaying in our React JS project.
    Then we added some nested data in JSON file. To display this nested data, we will use Array map inside Array map or map inside map. We already have the JSON data object. We will just extract values from it further. Unique key is needed for each record so that it can be identifiable by the app in case you need to get a single record.
    Unique Key prop is needed. We hard coded unique IDs in JSON file but you can get a package from npm to better handle unique IDs. For example UUID. You can take any type of JSON file, call it in React component with any name, map it's data and display records from it easily. You can use JSON file as a temporary database for the react app if you need it.
    Display Icons / Images in React JS | React JSON Tutorial
    • Display Icons / Images...
    7 Ways to use Images in React JS
    • 7 Ways to Use Images i...
    Easy Way to use Images in React JS | No Import | No Require
    • Easy Way to Use Images...
    Require Image Not Working in React JS
    • Require Image Not Work...
    Multiple Images in One Import
    • Multiple Images in ONE...
    Multiple Sets of Images from One Import in React JS
    • Multiple Sets of Image...
    Display Records or Data from JSON File in React JS
    • Display Records or Dat...
    Default Map is not a Function in React JS
    • Default MAP is Not a F...
    Async Await Fetch in React JS
    • Multiple Ways of Async...
    ReactJS Playground
    • ReactJS Playground
    Thank You!
    👍 LIKE VIDEO
    👊 SUBSCRIBE
    🔔 PRESS BELL ICON
    ✍️ COMMENT
    Channel: / webstylepress
    Website: www.webstylepress.com
    FaceBook: / webstylepress
    Twitter: / webstylepress
    GitHub: github.com/webstylepress
    #WebStylePress #ReactJS #React #JavaScript #JS #JSON #WebDevelopment #Data #Fetch #Map

Комментарии • 66

  • @trinity1641
    @trinity1641 11 месяцев назад +2

    Need more people like you thank you so much!

  • @ticia_games
    @ticia_games Год назад +4

    Voce é o salvador da pátria. Sinceramente! Obrigada amigo, voce é um amigo

  • @justme364
    @justme364 2 года назад +7

    Super solid tutorial, thank you!!!!

    • @webstylepress
      @webstylepress  2 года назад

      Plz give the video a like and subscribe to channel. It will help the channel.

  • @user-dx1ry7wf2y
    @user-dx1ry7wf2y 3 месяца назад +1

    Excellent and very clear explanation. Thank you so much!

  • @jhalmu
    @jhalmu Год назад +3

    Nice clean explanation, thanks

  • @lars-010
    @lars-010 Год назад +1

    Easy to understand , thanks !

  • @mvsrcm6413
    @mvsrcm6413 2 года назад +2

    thanks alot sir time saving for me! just subscribed

  • @harrychaklader
    @harrychaklader 10 месяцев назад

    Thanks, huge help for my hackathon.

  • @dougcontreras2665
    @dougcontreras2665 Год назад +1

    Thanks a lot, very helpful!

  • @arshots
    @arshots Год назад +3

    Thanks for the wonderful video. What if we need to provide/upload the JSON file using the rather than hard coding via import data from '../example.json' ?. Thanks.

  • @rhiannonbronnimann3548
    @rhiannonbronnimann3548 Год назад +2

    Thank you!!!! So helpful

  • @parveen545
    @parveen545 2 года назад +2

    this is an amazing video.

  • @CodeWithJJ
    @CodeWithJJ 2 года назад +1

    you explained well, thansk

  • @cyruspusa3836
    @cyruspusa3836 Год назад +1

    Thank you this really helps

  • @mira10045
    @mira10045 Год назад +1

    I subscribed. Thanks alot!

  • @keshavverma7195
    @keshavverma7195 2 года назад +1

    worked!! thanks

  • @lucasdamasceno7068
    @lucasdamasceno7068 Год назад +1

    thanks broo helped me a lot

  • @chukanano
    @chukanano 11 месяцев назад +1

    thank you so much. very nice

  • @funterban6536
    @funterban6536 10 месяцев назад

    beautiful explanation

  • @ajk6690
    @ajk6690 Год назад +1

    U help me so much tyyy ♥

  • @lifeatweb
    @lifeatweb 2 года назад +2

    Muito bom! Bem didático!

    • @_jeff.medeiros
      @_jeff.medeiros 2 года назад

      didático mesmo, esses caras salvam demais velho pqp

  • @bigbitdev9711
    @bigbitdev9711 2 года назад +1

    Bro you are the best I will subscribe!

  • @Ifrit_desu
    @Ifrit_desu Год назад

    Thanks for the great video! How would i go about adding a link to obj i got from the json file?

  • @muhammadbangkit7528
    @muhammadbangkit7528 2 года назад

    I have a question, if u want to render it but ordering let say ordering by price, how do you do that?

  • @insanuljihat8462
    @insanuljihat8462 2 года назад +1

    thanks,, nice tutorial,,

  • @mrnabby4178
    @mrnabby4178 Год назад +1

    Thanks bro. This was helpful.

  • @THEMYSTERIOSWORLD
    @THEMYSTERIOSWORLD 5 месяцев назад +1

    Great work

  • @Soc-Analyst-Security
    @Soc-Analyst-Security Год назад

    Is there an alternative to write data in json files as you are teaching here? without axios/fetch, json server?

  • @NYC_CuriousG
    @NYC_CuriousG Год назад

    Thank you for this video! Makes sense now. Question - what if in the JSON you are using from an API doesn't have ids hardcoded? Can you somehow assign it? (line 19 in your code)

  • @bunyameennurudeen173
    @bunyameennurudeen173 Год назад

    Thanks Dev.
    This is awesome and very educative but what of in a situation whereby there's a pure objects in the array like having a sub object as we have for array.
    Example:- languages: {
    ara: "Arabic"
    },
    which are different across the three items
    Thanks Dev

  • @dominiquesimbillo9437
    @dominiquesimbillo9437 Год назад +2

    quality content more video please

  • @soumyadipmajumder902
    @soumyadipmajumder902 Год назад

    If somebody create the json file under public folder then how to import in the source page folder? please reply...

  • @JoaoJGabriel
    @JoaoJGabriel Год назад +1

    Thank you, thank you, thank you

  • @akporraphael9069
    @akporraphael9069 6 месяцев назад

    In my vs code I don't get intellisense for json. What may be the problem?

  • @lifeatweb
    @lifeatweb 2 года назад +1

    Thanks a lot

  • @techdockerz
    @techdockerz 2 года назад +1

    Thanks Buddy

  • @mdtamizuddin4269
    @mdtamizuddin4269 2 года назад +1

    Thanks Bro 😘😍

  • @illidrissimouad2765
    @illidrissimouad2765 5 месяцев назад

    what about feting data depending on the id you clik on it on the link...?

  • @shravanp8091
    @shravanp8091 2 года назад

    can you make a video on how to read json data from AWS for a react web app?

  • @manuelbattaglia1390
    @manuelbattaglia1390 Год назад

    nice, but I can't execute the file, would you explain me how to do it? thank u so much

  • @ajayanandrao3446
    @ajayanandrao3446 Год назад +1

    Thank you

  • @synologictips2451
    @synologictips2451 Год назад

    Then how u fetch if u have like 20-30 json data?

  • @kanyshaiosmonova7968
    @kanyshaiosmonova7968 Год назад +1

    thank you

  • @edberaga
    @edberaga Год назад

    Why I got this error
    Uncaught TypeError: _common_json__WEBPACK_IMPORTED_MODULE_2__.map is not a function
    My map isn't a function??

  • @programminghead
    @programminghead Год назад +1

    In my case i didn't used the Record &&
    And was dealing with the error "can not read the property (map)"
    Thanks for your help

  • @Restricted-028
    @Restricted-028 Год назад +1

    can we use this mock json data to use as a storage to save and delete data

    • @webstylepress
      @webstylepress  Год назад

      Yes. Have a look at this.
      Node React JSON File Records Full Stack Local CRUD App Tutorial
      ruclips.net/video/lFkBk3f6Xww/видео.html

  • @LGmediaGlobal
    @LGmediaGlobal 2 года назад

    What happens when JSON file is from an external API and cannot recognize :id ?

    • @webstylepress
      @webstylepress  2 года назад

      Then u need to fetch data in useEffect and then use it. Simple import won't work. Plz give the video a like and subscribe to channel. It will help the channel.

  • @sidd_shaikh
    @sidd_shaikh Год назад

    HOW TO SET IMAGE URL?

  • @kenzafilali9115
    @kenzafilali9115 2 года назад +1

    nice

  • @kshitijkarkera452
    @kshitijkarkera452 Год назад

    Can we set a limit of items to be mapped?

    • @webstylepress
      @webstylepress  Год назад +1

      Yes. You can use Array slice. For example Data.slice(0, 5).map() ...

    • @kshitijkarkera452
      @kshitijkarkera452 Год назад +1

      @@webstylepress Thanks

  • @memelogy8507
    @memelogy8507 2 года назад

    Theme name pls

    • @webstylepress
      @webstylepress  2 года назад

      Ayu Dark Bordered - Plz give the video a like and subscribe to channel. It will help the channel.

  • @celilhn
    @celilhn 2 года назад

    where is the fetch??????

    • @webstylepress
      @webstylepress  2 года назад

      Fetch not needed. You can use it though. Use useEffect and fetch.

  • @vashimaryan85
    @vashimaryan85 Год назад

    Hi sir I need your help

    • @vashimaryan85
      @vashimaryan85 Год назад

      Can you give me code for this program