top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

    Get Free Article Updates

Facebook Login
Site Registration
Print Preview

Advantages of JSON

0 votes
14 views

Advantages of JSON

                                                           

JSON is primarily used for serializing and de-serializing data being sent to and from an application made using JavaScript. Considering this fact, the advantages of JSON relate to the use of JSON over other option for serialization  and de-serialization.

Typically, in an XML environment, the sender  encodes the data to serialized, by using a DTD that the recipient can comprehend. This task involves a lot of additional padding around the data, regardless of which DTD in use. Thus the size of the XML documents  is significantly  larger than the actual data values to be sent. Then, the recipient obtains the XML data stream and decodes it for putting in the memory.

Comparatively, this process of serialization if done through JSON is quicker and more compact due to the format’s inherent structure. JSON structure uses standard programming data types whose structure is simple to understand. Further, the encoding mechanism is efficient enough to add only minimum characters required to reflect the structure and data values. When the recipient obtains this serialized data, the only procedure required is to evaluate the text through a compatible function in any programming language. For example, evaluation can happen by using eval function of JavaScript.

The other standard to compare is Yaml Ain’t Markup Language (YAML) that serializes  complex data sets without a DTD and relies on a simpler parser than XML. Even such a parser consumes more time than JSON to output larger streams of serialized data.

Following are some more benefits of using JSON:

  • JSON parses faster than XML and YAML.
  • JSON is simpler to work with some languages such as PHP, Python, and JavaScript.
  • JSON is  simpler to map to an object oriented system, as it is data-oriented.
  • JSON is a valid subset of even Python and YAML apart from JavaScript.
  • JSON easily differentiates between the string ‘2’ and the number ‘2’ as well as between a single item and a collection of size one (array).
  • JSON is an ideal data exchange format, and not an ideal document exchange format as XML. Thus, it is not necessary for JSON to be extensible for exchanging documents by defining new tags for representing data.
posted Nov 13 by Gn Guruswamy

  Promote This Article
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button


Related Articles

JSON Support with Programming Languages

Each major programming language can incorporate JSON, which can be through either libraries or native support. However, no language can surpass JavaScript for parsing this data interchange format, which translates it directly into an object literal.

JSON is a popular as XML. Thus, each major language has one or more commonly used powerful libraries for formatting and parsing data in JSON format. Typically, only following two core functionalities are required:

  • Parse: Converts JSON data into the supported data structure of corresponding language, such as array, hash, or dictionary.
  • Format: Converts array, hash, or dictionary to JSON text.

Developers can easily find these functionalities for almost any modern language. For instance, Ruby incorporates JSON gem, Objective-C supports JSONKit, and Microsoft .NET Framework has Json.NET. Most of these libraries are fast and efficient, considering their extensive use and frequent optimizations over time.

While comparing various languages, it might be pointed out by some developers that using JSON in a C# or Java language is not practical. This is because the idioms supports statically typed classes and not objects of Dictionary or HashMap type. As a result, for generating JSON data, developers are required to use a library along with a custom code for converting these data structures to static type instances. Hence, there are some libraries created for this purpose. For instance, the Gson library from Google is designed for transforming JSON data to Java objects directly.

Gson

Gson is an open-source Java library for transforming an object in Java to JSON data and vice-versa. For this purpose, it offers easy means such as constructor (Factory Method) and toString(). This library also functions well with arbitrary Java objects, involving the pre-existing ones whose source code is not available with you. Following are the goals of Gson:

  • Converting already existing not-modifiable objects to and from JSON
  • Permitting custom representations for objects
  • Outputting legible and compact JSON data

Gson is capable of deserializing string of more than 25MB, deserializing 87,000 objects, and serializing of 1.4 million objects without any issues. Its 1.4 version has increased the deserialization bar from 80KB to more than 11MB, applicable for array and collections in bytes.

It is convenient to learn and use Gson. A developer needs to know two methods namely, toJson() and fromJson(). The toJson() method is used for transforming a Java object to JSON data whereas fromJson() for converting JSON data to an object in Java.

READ MORE
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...