IT TIP

json과 xml의 차이점은 무엇입니까

itqueen 2020. 10. 22. 23:51
반응형

json과 xml의 차이점은 무엇입니까


JSON과 XML의 차이점은 무엇입니까?


다른 답변이 언급하지 않은 것 같은 근본적인 차이점은 XML이 마크 업 언어 (실제로 이름에서 말했듯이) 인 반면 JSON은 객체를 나타내는 방법이라는 것입니다 (이름에서도 언급 됨).

마크 업 언어는 자유 흐름이있는 일반 텍스트에 추가 정보를 추가하는 방법입니다.

Here is some text.

XML (특정 요소 어휘 사용)을 사용하면 다음을 넣을 수 있습니다.

<Document>
    <Paragraph Align="Center">
        Here <Bold>is</Bold> some text.
    </Paragraph>
</Document>

이것은 마크 업 언어가 문서를 표현하는 데 매우 유용하게 만드는 이유입니다.

JSON과 같은 객체 표기법은 그다지 유연하지 않습니다. 그러나 이것은 일반적으로 좋은 것입니다. 개체를 표현할 때 추가 유연성이 필요하지 않습니다. 위의 예를 JSON으로 표현하려면 실제로 XML이 해결하는 몇 가지 문제를 수동으로 해결해야합니다.

{
    "Paragraphs": [
        {
            "align": "center",
            "content": [
                "Here ", {
                    "style" : "bold",
                    "content": [ "is" ]
                },
                " some text."
            ]
        }
    ]
}

XML만큼 좋지 않으며 그 이유는 객체 표기법으로 마크 업을 수행하려고하기 때문입니다. 따라서 우리는 문자열과 중첩 된 객체의 혼합을 보유 할 수있는 "콘텐츠"배열을 사용하여 객체 주변에 일반 텍스트 조각을 분산시키는 방법을 개발해야합니다.

반면에 일반적인 객체 계층이 있고 스트림으로 표현하려는 경우 JSON이 HTML보다이 작업에 더 적합합니다.

{
    "firstName": "Homer",
    "lastName": "Simpson",
    "relatives": [ "Grandpa", "Marge", "The Boy", "Lisa", "I think that's all of them" ]
} 

논리적으로 동등한 XML은 다음과 같습니다.

<Person>
    <FirstName>Homer</FirstName>
    <LastName>Simpsons</LastName>
    <Relatives>
        <Relative>Grandpa</Relative>
        <Relative>Marge</Relative>
        <Relative>The Boy</Relative>
        <Relative>Lisa</Relative>
        <Relative>I think that's all of them</Relative>
    </Relatives>
</Person>

JSON은 프로그래밍 언어로 선언하는 데이터 구조와 비슷합니다. 또한 중복되는 이름이 적습니다.

그러나 가장 중요한 것은 "레코드"(순서가없는 항목, 이름으로 식별되는 항목)와 "목록"(순서가 지정된 항목, 위치로 식별되는 항목)을 구분하는 정의 된 방법이 있다는 것입니다. 객체 표기법은 그러한 구분 없이는 사실상 쓸모가 없습니다. 그리고 XML에는 그런 구별이 없습니다! 내 XML 예제 <Person>에서 레코드이고 <Relatives>목록이지만 구문으로 식별되지 않습니다.

대신 XML에는 "요소"대 "속성"이 있습니다. 이것은 같은 종류의 구별처럼 보이지만 속성은 문자열 값만 가질 수 있기 때문에 그렇지 않습니다. 중첩 된 개체 일 수 없습니다. 그래서이 아이디어를에 적용 할 수 없었습니다 <Person>. 왜냐하면 <Relatives>단일 문자열 로 바꿀 필요가 없었기 때문 입니다.

외부 스키마 또는 추가 사용자 정의 속성을 사용하여 XML의 목록과 레코드 간의 구분을 공식화 할 수 있습니다. JSON의 장점은 저수준 구문에 이러한 구분이 내장되어있어 매우 간결하고 보편적이라는 것입니다. 이는 JSON이 기본적으로 더 "자기 설명"이라는 것을 의미하며, 이는 두 형식의 중요한 목표입니다.

따라서 JSON은 객체 표기법의 첫 번째 선택이되어야합니다. XML의 가장 좋은 점은 문서 마크 업입니다.

안타깝게도 XML의 경우 이미 세계 최고의 리치 텍스트 마크 업 언어로 HTML이 있습니다. XML의 관점에서 HTML을 재구성하려는 시도가 있었지만이 점에서 큰 이점은 없습니다.

그래서 XML은 (제 생각에) 꽤 제한된 틈새 기술이어야했고, 어떤 이유로 든 HTML을 사용하고 싶지 않은 경우에만 고유 한 리치 텍스트 마크 업 언어를 개발하는 데 가장 적합해야합니다. 문제는 1998 년에도 여전히 웹에 대한 과대 광고가 많았고 XML이 HTML과 겉으로보기에 닮아서 대중화되었다는 것입니다. 편리한 마크 업을 위해 실제로 설계된 구문을 계층 적 데이터에 적용하려는 것은 이상한 디자인 선택이었습니다.


둘 다 계층 적 데이터에 대한 데이터 형식이므로 구문은 상당히 다르지만 구조는 비슷합니다. 예:

JSON :

{
  "persons": [
    {
      "name": "Ford Prefect",
      "gender": "male"
    },
    {
      "name": "Arthur Dent",
      "gender": "male"
    },
    {
      "name": "Tricia McMillan",
      "gender": "female"
    }
  ]
}

XML :

<persons>
  <person>
    <name>Ford Prefect</name>
    <gender>male</gender>
  </person>
  <person>
    <name>Arthur Dent</name>
    <gender>male</gender>
  </person>
  <person>
    <name>Tricia McMillan</name>
    <gender>female</gender>
  </person>
</persons>

The XML format is more advanced than shown by the example, though. You can for example add attributes to each element, and you can use namespaces to partition elements. There are also standards for defining the format of an XML file, the XPATH language to query XML data, and XSLT for transforming XML into presentation data.

The XML format has been around for some time, so there is a lot of software developed for it. The JSON format is quite new, so there is a lot less support for it.

While XML was developed as an independent data format, JSON was developed specifically for use with Javascript and AJAX, so the format is exactly the same as a Javascript literal object (that is, it's a subset of the Javascript code, as it for example can't contain expressions to determine values).


The difference between XML and JSON is that XML is a meta-language/markup language and JSON is a lightweight data-interchange. That is, XML syntax is designed specifically to have no inherent semantics. Particular element names don't mean anything until a particular processing application processes them in a particular way. By contrast, JSON syntax has specific semantics built in stuff between {} is an object, stuff between [] is an array, etc.

A JSON parser, therefore, knows exactly what every JSON document means. An XML parser only knows how to separate markup from data. To deal with the meaning of an XML document, you have to write additional code.

To illustrate the point, let me borrow Guffa's example:

{   "persons": [
  {
    "name": "Ford Prefect",
    "gender": "male"
 },
 {
   "name": "Arthur Dent",
   "gender": "male"
  },
  {
    "name": "Tricia McMillan",
    "gender": "female"
  }   ] }

The XML equivalent he gives is not really the same thing since while the JSON example is semantically complete, the XML would require to be interpreted in a particular way to have the same effect. In effect, the JSON is an example uses an established markup language of which the semantics are already known, whereas the XML example creates a brand new markup language without any predefined semantics.

A better XML equivalent would be to define a (fictitious) XJSON language with the same semantics as JSON, but using XML syntax. It might look something like this:

<xjson>   
  <object>
    <name>persons</name>
    <value>
      <array>
         <object>
            <value>Ford Prefect</value>
            <gender>male</gender>
         </object>
         <object>
            <value>Arthur Dent</value>
            <gender>male</gender>
         </object>
         <object>
            <value>Tricia McMillan</value>
            <gender>female</gender>
         </object>
      </array>
    </value>   
  </object> 
 </xjson>

Once you wrote an XJSON processor, it could do exactly what JSON processor does, for all the types of data that JSON can represent, and you could translate data losslessly between JSON and XJSON.

So, to complain that XML does not have the same semantics as JSON is to miss the point. XML syntax is semantics-free by design. The point is to provide an underlying syntax that can be used to create markup languages with any semantics you want. This makes XML great for making up ad-hoc data and document formats, because you don't have to build parsers for them, you just have to write a processor for them.

But the downside of XML is that the syntax is verbose. For any given markup language you want to create, you can come up with a much more succinct syntax that expresses the particular semantics of your particular language. Thus JSON syntax is much more compact than my hypothetical XJSON above.

If follows that for really widely used data formats, the extra time required to create a unique syntax and write a parser for that syntax is offset by the greater succinctness and more intuitive syntax of the custom markup language. It also follows that it often makes more sense to use JSON, with its established semantics, than to make up lots of XML markup languages for which you then need to implement semantics.

It also follows that it makes sense to prototype certain types of languages and protocols in XML, but, once the language or protocol comes into common use, to think about creating a more compact and expressive custom syntax.

It is interesting, as a side note, that SGML recognized this and provided a mechanism for specifying reduced markup for an SGML document. Thus you could actually write an SGML DTD for JSON syntax that would allow a JSON document to be read by an SGML parser. XML removed this capability, which means that, today, if you want a more compact syntax for a specific markup language, you have to leave XML behind, as JSON does.


They're two different ways of representing data, but they're pretty dissimilar. The wikipedia pages for JSON and XML give some examples of each, and there's a comparison paragraph


They are two formats of representation of information. While JSON was designed to be more compact, XML was design to be more readable.


XML uses a tag structures for presenting items, like <tag>item</tag>, so an XML document is a set of tags nested into each other. And JSON syntax looks like a construction from Javascript language, with all stuff like lists and dictionaries:

{
 'attrib' : 'value',
 'array' : [1, 2, 3]
}

So if you use JSON it's really simple to use a JSON strings in many script languages, especially Javascript and Python.

참고URL : https://stackoverflow.com/questions/2620270/what-is-the-difference-between-json-and-xml

반응형