mysql - Code for convert db data into json file -


i have list of entity(id,email,empname,designation) called dblist. want json file contain json array of json.

import org.primefaces.json.jsonarray;

import org.primefaces.json.jsonobject;

import java.io.filewriter;

import java.io.ioexception;

jsonobject objbig = new jsonobject(); jsonarray company = new jsonarray();          dblist.foreach(e -> {                  jsonobject obj = new jsonobject();                 obj.put("id", e.getuserprincipalname());                 obj.put("email", e.getemail());                 obj.put("empname", e.getempname());                 obj.put("designation", e.getdesignation());                  company.put(obj);                     }); objbig.put("data", company);  string path = "c:/xyz";         filewriter file = null;         try {             file = new filewriter(path);             file.write(objbig.tostring());             log.info("successfully copied json object file...");             log.info("\njson object: " + objbig);         } catch (exception e) {             log.error(e.getmessage());         } {             if (file != null) {                 file.flush();                 file.close();                 log.info("getemployeejson ended");             }         } 


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -