How to Read Data from JSON file using JAVA Code

preview_player
Показать описание
Hello

In this tutorial, I will show you How to Read data from a Json file in Java | Selenium

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

The JSON-simple is a lightweight library that is used to process JSON objects. Using this you can read or, write the contents of a JSON document using Java program

maven dependency for the JSON-simple library

Please do subscribe for more tutorials on selenium automation @SH Study Tech

Please share questions and queries in the comments section.

Follow me on Twitter: shstudy

Рекомендации по теме
Комментарии
Автор

Sureh, thanks for video . I have a question and need solution, if I can get please? I have a dynamic json, which is actually an export of PCAP file from wireshark. It comes as a Jason array OR json object and keys and data are not known in advance. i.e. after reading file we need to find out keys and values (note there could be nested arrays and objects within json). How do we parse and read these files please? So I need to first know whether it's a Json array or object & then parse the file, then identify keys and arrays inside json and then be able to process/print it? Is there a solution for this please?

nitindixit
Автор

Thanks. But if i add more than one information in JSON file, how can I read?

Userabs
Автор

Simple and cool explanation, it helps me a lot, thanks you.

mallikharjunchilaka
Автор

Thanks, can you do the same for JSON ARRAY?

AjithKumar-jbke
Автор

How to modify and pass the payload when we have multiple data

dewanganskitchen
Автор

I followed your video but I am getting below error at line 21 of your video reference,

class org.json.simple.JSONArray cannot be cast to class org.json.simple.JSONObject



Please do help!

sainiranjan
Автор

Great Tutorial, Can you make another video where you show how to write into a json file?

styledman
Автор

how to create a json file ?will please share the video also.

mahiborra
Автор

Hi, the video is helpful, but I'm getting below error, please look into this and let me know how to fix it:

Error: Unable to initialize main class jsonFiles.ReadingJsonFile
Caused by:


I'm using the same code as mentioned by you and have json simple jar as well.

anuradhatarekar