Artikel Terbaru

Sunday, 7 August 2016

XML and JSON basics

JSON Basics:-

JSON is java script Object notation. JSON is independentent format for exchaning data JSON is simple format which contain key pair values. JSON and xml are data formats used to transfer data between different systems of enterprise applications . JSON is lightweight and simple to read

JSON Sample data file

{ "id" : 1.0, "name" : "Kiran", "sal" : 5000, }
     {
        "id" : 1.0,
        "name" : "Kiran",
        "sal" : 5000,
    }

XML Basic meaning:-

XML is extensive markeuplanguage which start and end tag and follows certain data validations. XML file can be validates with XML Schema. XML files has data attributes. Reading xml is very easy as most of browsers and editors support simple clicable readable format.

xml sample data file:

Sub tag
Most of companies which offers REST APIS expose the data in either XML or JSON. Clients consume those REST API's and use programming technicque to process xml/json data XML and JSON data can be read easily by programmers. Both xml and json are not similar. There are many ways to convert xml to json
We have many ways to convert json to xml in java

How to convert json to xml in java

com.gson.gson library provides for reading JSON object and XML class will convert into XML object
import org.json.JSONObject;
import org.json.XML;

public class JsonToXmlConvert {
 public static void main(String[] args) throws Exception {
  String jsonObject = "{'json key':'json value'}";  
  JSONObject json = new JSONObject(jsonObject);
  String xml = XML.toString(json);

 }
}