W
W
wol2for2017-02-23 16:47:44
JavaScript
wol2for, 2017-02-23 16:47:44

Differences between XML and JSON?

Can you tell me the main theses in the difference between XML and JSON?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Ruslan Polin, 2017-02-23
@wol2for

XML is a markup language.

<widget>
    <debug>on</debug>
    <window title="Sample Konfabulator Widget">
        <name>main_window</name>
        <width>500</width>
        <height>500</height>
    </window>
    <image src="Images/Sun.png" name="sun1">
        <hOffset>250</hOffset>
        <vOffset>250</vOffset>
        <alignment>center</alignment>
    </image>
    <text data="Click Here" size="36" style="bold">
        <name>text1</name>
        <hOffset>250</hOffset>
        <vOffset>100</vOffset>
        <alignment>center</alignment>
        <onMouseUp>
            sun1.opacity = (sun1.opacity / 100) * 90;
        </onMouseUp>
    </text>
</widget>

JSON is a format for data exchange, in many languages ​​it is implemented as an array of data.
"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    },
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}

V
Viktor Yanyshev, 2017-02-23
@villiwalla

Working with XML through DOM, JSON through an object. Where it is less and easier to write code, obviously.

R
Rou1997, 2017-02-23
@Rou1997

With JS ON, it is much more convenient to work with JS than with XML, and, for example, PHP too, and there are libraries for other modern languages, so JSON support is more priority, but if the API will be used by a large audience, or there will be clients using tools like Delphi 7, you also need XML support.
And there is also an option to return HTML, this is for server rendering of parts of pages, but it is convenient for the client to work with this only if it is a browser, in fact HTML is not XML, parsing it using XML tools is unacceptable, as well as, obviously, using tools for JSON, that is, without a browser (or "engine" from the browser), consider it in any way.

R
Rafael™, 2017-02-23
@maxminimus

xml and html are related languages ​​- this is a tree type data structure
json is a text data format originally from js
designed to exchange data between programs

V
vintage, 2017-02-23
@vintage

There is a comparison of XML, JSON and 3 more formats: https://habrahabr.ru/post/248147/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question