- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create and write JSON array to a file in java?
Java provides javax.json.Json package which contains classes to read a JSON array:
Example
import java.io.FileOutputStream; import javax.json.Json; import javax.json.JsonArray; import javax.json.JsonWriter; public class JSONArrayToFile { public static void main(String args[]) throws Exception { JsonArray value = Json.createArrayBuilder() .add(Json.createObjectBuilder() .add("id", "1001") .add("Technology", "JavaFX")) .add(Json.createObjectBuilder() .add("id", "1002") .add("Technology", "OpenCV")) .build(); System.out.println(value); JsonWriter writer = Json.createWriter(new FileOutputStream("sampleData")); writer.writeArray(value); writer.close(); } }
Output
["JavaFX","HBase","JOGL","WebGL"] After deleting ::["JavaFX","HBase","JOGL"]
- Related Articles
- How to Write/create a JSON file using Java?
- How to Write/create a JSON array using Java?
- How can we write JSON objects to a file in Java?\n
- How to write a JSON string to file using the Gson library in Java?
- How to create a JSON Array using Object Model in Java?
- How to add a JSON string to an existing JSON file in Java?
- How to write contents of a file to byte array in Java?
- Java Program to write int array to a file
- How to create a JSON using JsonObjectBuilder and JsonArrayBuilder in Java?
- How to convert a JSON array to array using JSON-lib API in Java?\n
- How to convert a JSON array to CSV in Java?
- Java Program to write an array of strings to a file
- How to convert a Collection to JSON Array using JSON-lib API in Java?
- How to create a pdf file in Java?
- How to convert Java Array/Collection to JSON array?

Advertisements