Json - Library

About

Library or software that can parse Json file

List

Language Name Description
Stream, File, Console jq a command-line JSON processor.
Java Org.Json org.json Parses a JSON (RFC 4627)
Java Jackson com.fasterxml.jackson.annotation.JsonCreator

Javascript

Language Name Description
Javascript text Directly as text
Javascript global JSON object ES5 introduced a new global JSON object for reading and writing (stringify) the JSON data format.
  • Node: Reading a JSON from a file
const dataObject = JSON.parse(fs.readFileSync('data/file.json').toString());
await util.promisify(fs.writeFile)('./dir/file.json', JSON.stringify(object, null, ' '));

Example

Javascript

  • Json can be read natively by javascript
// a variable
var human = {  
     name : "Robot",
     sex : "Unknown"        
}
// we call the function  
console.log(human.name+" has a "+ human.sex+ " sex"); 
// a variable
var humanObject = {  
     name : "Robot",
     sex : "Unknown"        
}
// we call the function  
console.log(JSON.stringify(humanObject)); 

Javascript Prettify

with spacing level = 2

var str = JSON.stringify(obj, null, 2); 

Java

Org.json - Java

String json = "{"
         + "  \"query\": \"Pizza\", "
         + "  \"locations\": [ 94043, 90210 ] "
         + "}";

 JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
 String query = object.getString("query");
 JSONArray locations = object.getJSONArray("locations");

Documentation / Reference


Powered by ComboStrap