Skip to content
Advertisement

How create a JSONArray in java

I have 2 java functions: listeFilesHdfs return a list of files that stored in HDFS, for example:

If you remark, the files that stored in HDFS there content is a JSON format, for example:

JavaScript

I created the below function to call both function above (one return list of files and the second open a path):

How can I modify my function to read the files content and to add each file content to the JSON array and return an array of JSON ? Thanks

Advertisement

Answer

As by your comment answer, you are looking for a way to parse the json content of the files into a javax.json-JsonArray.

The answer is the class JsonReader. As per the documentation:

JavaScript

That JsonStructure could then be a JsonArray (and you may cast to it, after checking the class).

It might work like this (though I can’t test it):

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement