Build failure in Json parsing

I am using What is JSON and How to iterate through the JSON object? as a reference for json parsing. But i am getting build failure when i read values from Trades.json.
Also, i am unable to find any solution from the error.

Are you able to parse the required data from JSON properly?

if not, take a look at this too (from references provided by crio itself)
you need to understand how to work with ObjectMapper. and converting JSON to Java Objects.

If you are able to see proper output in your terminal, but had build failure, you can refer this

No, i can’t even parse the required data from JSON .I am unable to understand how to correct my code ?

You have to write a POJO for the same.

Refer to this

Hi, try going through these links as well, in addition to the FAQ mentioned

These should help you :slight_smile:

But in FAQs What is JSON and How to iterate through the JSON object? it is mentioned that ’ Note : For the given task, you do not have to declare a POJO , a POJO class called is provided for the same , where the values from Trades.json have to be read.’

The links you have provided are of module 2. I am currently stuck in module 1 milestone 1.

My bad :sweat_smile:

What exactly is the error you are facing?
Or which step of the relevant FAQ isn’t clear/working for you?

Yes, you are right.
And for this task it is enough that you work with what is already provided to you. The functions provided by them itself is enough to complete the task.

Read TODOs carefully, first two points tells you what to use.

You need to parse the json file, so first you need to get that file using resolveFileFromResources.
Then use getObjectMapper & explore different options.
To begin with, It’s better you start with printing result on console using System.out.println()

I am unable to parse the desired output from JSON file. I used the command written in FAQs link that i have given, but when i run gradlew it is giving build failure. I am not getting how to write the code to parse the desired output since i am coding in java for the first time .

Yes you can also use class to parse json by creating objects of this class.

If you go through the task TODOs step by step, it lists out the process and the methods you need to use. First you need to get the file, then use ObjectMapper and then implement the rest of the method. Try doing it one step at a time and reading through the FAQs for Module 1, which have the links detailing the complete code you need to write.

Thank you everyone for the hints. Working on it !

1 Like

“unreported exception IOException; must be caught or declared to be thrown”
How to throw IO Exception ?

How to throw IO Exception? >>>>>>> throw new IOException(“message here”);

we use try catch block…our code inside try, thinking it might throw an exception

But let me know what you were trying to do. n What generated this? “Cz We don’t work with all those here.”

I created object of class and then iterated through this object .

My approach was I observed the data type of the return values from functions, the parameters, arguments and understanding ObjectMapper and using getObjectMapper() function that was already given to us. And this was sufficient for me to complete the given task. Additionally I used Java lists and JsonNode.

And since you said you are new to Java, try this…just type getObjectMapper(). and it will show you available methods. Understand the usage of them.

Yess…You were doing the right thing…!

Yes your going in right direction!

for more you can understand json parsing from here!!

Create an object list and read all json values in the list of objects.
This is a good reference for using Jackson ObjectMapper: