0

I am automating a registration form that has various fields such as Name, Email, Phone etc. and I wish to pass data to the form without using Excel or CSV files, and I want to use JSON/XML instead. Now I have no clue how to achieve that, would be very helpful if someone can tell me what dependencies I need to use and how do I go about it.

1
  • What you had tried? Commented Sep 18, 2021 at 13:12

1 Answer 1

2

As you want to read the JSON and pass the data to scripts but we don't know your JSON so I am assuming the JSON in below format.

JSON:

{
    "name":"Nandan",
    "email":"[email protected]",
    "phone":1234567890
 }

Maven dependency:

<dependency>
     <groupId>org.json</groupId>
     <artifactId>json</artifactId>
     <version>20160212</version>
 </dependency>

Imports:

import org.json.JSONObject;

Read and get data from JSON:

String jsonDataAsString = new String(Files.readAllBytes(Paths.get("C:\\Users\\Sample.json")));
         
JSONObject jsonData = new JSONObject(jsonDataAsString);
System.out.println(jsonData.get("name"));
System.out.println(jsonData.get("email"));
System.out.println(jsonData.get("phone"));

Output:

Nandan
[email protected]
1234567890
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.