Why is Everyone Choosing JSON Over XML for jQuery ?

Why is Everyone Choosing JSON Over XML for jQuery ?

Asked on December 21, 2018 in XML.
Add Comment

  • 3 Answer(s)

    JSON over xml for jquery:

         JSON is recognized natively by JavaScript, it is lightweight, minimalistic and highly portable because it relies only on two fundamental structures:

    • A collection of name/value pairs. It is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array in other languages.
    • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
    Answered on December 21, 2018.
    Add Comment

    Follow this answer:

         Start mixing together different namespaced schemas, the XML does not begin to shine until that. Then JSON start to fall down, but if need a serialization format for the data, JSON is smaller, lighterweight, more human readable, and faster than XML.

    Answered on December 21, 2018.
    Add Comment

    Here is the statement:

         There are more ways to do even simple data structures in XML — as elements, as attribute values, etc. Then have to document it, write up XML Schema or Relax NG or some other crap.

    The XML will have its asset, but for data interchange. JSON is more compact and direct. There is no mismatch between the simple data types in JSON and in Python. So if a server-side handler for an AJAX query that was  about snow conditions for a particular Ski resort, some dictionary like,

    conditions = {
      'new_snow_24': 5.0,
      'new_snow_48': 8.5,
      'base_depth': 88.0,
      'comments': 'Deep and steep!',
      'chains_required': True,
    return simplejson.dumps(conditions) # Encode and dump `conditions` as a JSON string

         When translated through JSON using a library like ‘simplejson’ for Python, the resulting JSON structure looks nearly identical (except in JSON, booleans are lower-cased).

    By decoding that structure requires a JSON parser, whether it is for Javascript or Objective-C for a native iPhone app or C# or a Python client. The floats may get interpreted as floats, the strings as strings, and booleans as booleans. By using the ‘simplejson’ library in Python, a simplejson.loads(some_json_string) statement would give back a full data structure.

    To write XML, decide that whether to do elements or attributes. 

      <comments>deep and steep!</comments>
    <conditions newSnow24="5" newSnow48="8.5" chainsRequired="yes">
      <comments>deep and steep!</comments>

         XML, while simple than plain SGML by being more strict with its rules,will provides many ways to think about that data. Then need to go for generating it. If not received an XML document and then immediately say “go make thyself into objects and data structures” without writing a custom parser, or without requiring the additional overhead of XML Schema/Relax NG and other such pains.

    It is easier and more direct to encode and decode data to JSON, especially for quick interchanges. This may apply more to people coming from a dynamic language background, and built in to JavaScript / JSON directly map to the same or similar data types in Python, Perl, Ruby, etc.

    Answered on December 21, 2018.
    Add Comment

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.