Skip to main content
CCNA Automation (200-901 CCNAAUTO) beginner Free with email

JSON vs XML: What's the Difference?

Reviewed 2026-11-23

Direct answer
JSON vs XML comes down to shape and strictness: JSON uses compact key-value pairs and suits REST APIs, while XML uses tags and suits SOAP, NETCONF and strict schemas. This free PDF is a three-page Postman quick reference, and this page adds YAML, RESTCONF and the CCNA Automation exam link.

What Is the Difference Between JSON and XML?

JSON vs XML comes down to shape and strictness. JSON writes data as key-value pairs inside braces and square brackets. XML wraps every value in opening and closing tags. JSON is shorter and is the usual pick for REST APIs. XML is stricter, and SOAP and NETCONF are built on it.

The table adds YAML, because Cisco’s CCNA Automation exam compares all three.

JSONXMLYAML
Stands forJavaScript Object NotationExtensible Markup LanguageYAML Ain’t Markup Language
ShapeObjects {} and arrays []A tree of elements and attributesIndentation, : and -
CommentsNone (RFC 8259 defines no comment syntax)<!-- note --># note
Data typesString, number, boolean, null, object, arrayEverything is text unless a schema says otherwiseScalars, lists and maps
ListsNative, [ ]Repeated elementsNative, - item
ValidationJSON Schema, a separate standardXSD or DTD, part of the XML familyNo built-in validation language
NamespacesNoYesNo
Typical useREST APIs, web and mobile appsSOAP, NETCONF, documentsConfig files such as Ansible and Docker Compose

The formal definitions are short: RFC 8259 for JSON, the W3C XML 1.0 specification, and the YAML 1.2.2 specification.

JSON vs XML vs YAML: The Same Router Record in Each Format

Here’s one record written three ways. I loaded all three in a parser and they produce identical data.

JSON:

{
  "hostname": "edge-rtr-01",
  "mgmt_ip": "192.0.2.10",
  "enabled": true,
  "interfaces": ["GigabitEthernet1", "GigabitEthernet2"]
}

XML:

<device>
  <hostname>edge-rtr-01</hostname>
  <mgmt_ip>192.0.2.10</mgmt_ip>
  <enabled>true</enabled>
  <interfaces>
    <interface>GigabitEthernet1</interface>
    <interface>GigabitEthernet2</interface>
  </interfaces>
</device>

YAML:

# Edge router record
hostname: edge-rtr-01
mgmt_ip: 192.0.2.10
enabled: true
interfaces:
  - GigabitEthernet1
  - GigabitEthernet2

Pretty-printed with two-space indents, the JSON file is 136 bytes, the XML file is 231 bytes and the YAML file is 131 bytes (that includes its comment line). XML runs about 70% larger here because every value repeats its name in a closing tag. With all whitespace stripped, the gap is 117 bytes for JSON against 204 for XML.

One small record isn’t a benchmark. Test your own payloads before you choose on size alone.

Go deeper

Exam topic 1.1 compares JSON, XML and YAML.

Practice them in the CCNA Automation Workbook: parse all three in Python and send RESTCONF requests.

See the CCNA Automation Workbook →

When Should You Use JSON vs XML?

Use JSON when:

  • You’re building or calling a REST API.
  • A web or mobile app reads the data. JavaScript turns a JSON string into an object with JSON.parse().
  • You want the least markup around your data.
  • You’re on Spring. JSON works with the default Jackson setup, while XML needs the jackson-dataformat-xml dependency (Spring reference).

Use XML when:

  • The service speaks SOAP. Every SOAP message is an XML envelope.
  • The protocol is NETCONF. RFC 6241 defines an XML-based data encoding for it.
  • You need strict validation with an XSD, or namespaces to mix vocabularies in one document.
  • You’re marking up documents. SVG images and RSS feeds are XML.

Use YAML when a person edits the file by hand and wants comments. Ansible playbooks and inventories and Docker Compose files are YAML.

One more rule of thumb: REST doesn’t force a data format, but SOAP and NETCONF do. So XML vs JSON isn’t a contest with one winner. The protocol and the person editing the file decide.

JSON vs XML by protocol: JSON for REST APIs and RESTCONF, XML for SOAP and NETCONF
In JSON vs XML, the protocol often decides: REST and RESTCONF can use JSON, while SOAP and NETCONF use XML.

Where Do Network Engineers Use JSON, XML and YAML?

On a Cisco IOS XE router you can meet all three in one week. NETCONF sends XML over SSH on TCP port 830 (RFC 6242). RESTCONF runs over HTTPS and accepts JSON or XML (RFC 8040). Ansible reads YAML files that you write by hand.

The NETCONF and YANG PDF covers the XML side in detail. The Ansible commands cheat sheet covers the YAML side. Need port numbers like 830 and 443 in one table? Use the common ports cheat sheet.

JSON vs XML vs YAML in network automation: RESTCONF uses JSON or XML, NETCONF uses XML on port 830, Ansible uses YAML
In network automation, RESTCONF accepts JSON or XML over HTTPS, NETCONF uses XML over SSH port 830, and Ansible inventories are YAML.

RESTCONF: One Interface, Two Encodings

With RESTCONF the client picks the format using the Accept header. RFC 8040 defines two media types for it: application/yang-data+json and application/yang-data+xml.

GET /restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet1 HTTP/1.1
Host: 192.0.2.10
Accept: application/yang-data+json

The same interface node, trimmed, comes back in either encoding. JSON prefixes the node with its YANG module name. XML declares a namespace instead. The JSON rules for YANG data are in RFC 7951.

{
  "ietf-interfaces:interface": {
    "name": "GigabitEthernet1",
    "description": "Uplink to core",
    "type": "iana-if-type:ethernetCsmacd",
    "enabled": true
  }
}
<interface xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"
           xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">
  <name>GigabitEthernet1</name>
  <description>Uplink to core</description>
  <type>ianaift:ethernetCsmacd</type>
  <enabled>true</enabled>
</interface>

A real reply has more leaves, and the exact path depends on the device and the YANG models it ships.

Ansible: YAML You Write by Hand

An Ansible inventory is a YAML file. It has no schema to read, only indentation, so a misaligned line is the usual failure.

# inventory.yml
all:
  hosts:
    edge-rtr-01:
      ansible_host: 192.0.2.10
      ansible_network_os: cisco.ios.ios

Is XML Obsolete?

No. It’s older than JSON and it’s no longer the default for new web APIs, but it’s still the format underneath SOAP, NETCONF and SVG. Many enterprise and banking systems still exchange XML, so you’ll meet it on the job.

XML does carry one risk that JSON doesn’t. An XML parser can resolve external entities from untrusted input, called XXE injection, which can expose local files or trigger server-side requests (OWASP). The fix is a parser setting: disable DTD processing and external entities. If you accept XML from outside your network, check that setting first.

How Do You Send JSON or XML in Postman?

Postman sends either format from the Body tab.

  1. Open the Body tab and choose raw.
  2. In the dropdown on the right, pick JSON or XML.
  3. Open the Headers tab. Postman sets Content-Type from the type you picked, and a header you add yourself takes precedence (Postman docs).

A JSON login body looks like this. Use placeholders, and don’t save real passwords in a collection you share.

{
  "username": "demo-user",
  "password": "CHANGE_ME"
}
Postman steps to send JSON or XML: Body raw, pick the format, check the Content-Type header
To send JSON or XML in Postman, open Body, choose raw, pick the format, then check the Content-Type header Postman set.

What Changes for a SOAP Request?

SOAP wraps the same fields in an envelope. SOAP 1.1 sends Content-Type: text/xml plus a SOAPAction header (W3C SOAP 1.1 Note). SOAP 1.2 uses application/soap+xml instead (RFC 3902). If your service needs text/xml, add your own Content-Type header in Postman, because yours wins.

POST /auth HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:example:auth/Login"
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <LoginRequest xmlns="urn:example:auth">
      <username>demo-user</username>
      <password>CHANGE_ME</password>
    </LoginRequest>
  </soap:Body>
</soap:Envelope>

The SOAPAction value comes from the service’s WSDL. The URN above is a placeholder.

JSON vs XML request headers: application/json and application/xml for REST, text/xml and SOAPAction for SOAP 1.1
A JSON vs XML request differs by header: REST can use application/json or application/xml, and SOAP 1.1 uses text/xml plus SOAPAction.

Which Syntax Mistakes Break JSON, XML and YAML?

Each format fails in its own way. I ran every case below through Python’s json, xml.etree and PyYAML parsers, and each one raised an error.

FormatMistakeWhy it fails
JSONA comma after the last itemJSON has no trailing commas
JSONSingle quotes around a string or keyStrings and keys need double quotes
JSONA // commentJSON has no comment syntax
JSONA key with no quotesKeys must be strings
XMLA start tag with no end tagThe document isn’t well-formed
XML<Name> closed by </name>XML is case-sensitive
XMLTwo root elementsA document has exactly one root
XMLA bare & in text& must be written &amp;
YAMLA tab used to indentThe spec says tabs must not be used in indentation
YAMLOne line indented differently from its siblingsIndentation is the structure

Which Format Does the CCNA Automation Exam Test?

Cisco’s 200-901 v1.1 blueprint lists topic 1.1 as “Compare data formats (XML, JSON, and YAML)”. It sits in section 1.0, Software Development and Design, which carries 15% of the exam (Cisco exam topics PDF).

The topic is a comparison, so the table at the top and the mistakes list above are your study material. For the rest of the exam, the blog post on Python skills for CCNA 200-901 and the guide to Python for network engineers show where these formats turn up in scripts.

What’s in the Free JSON vs XML PDF, and Where Does It Stop?

The PDF is a three-page quick reference. It explains what Postman is used for, defines JSON and XML with one example each, says when to use each, lists the Postman body settings, shows a JSON login body and an XML login body, compares the two in a six-row table and ends with a two-sentence interview answer.

It stops at the basics. There’s no YAML, no RESTCONF or NETCONF, and no link to the exam. The CCNA Automation Workbook picks up from there, with Python fundamentals that include JSON, XML and YAML parsing, plus RESTCONF GET and PATCH requests.

Free JSON vs XML PDF next to the CCNA Automation Workbook, which adds JSON, XML and YAML parsing and RESTCONF labs
The free JSON vs XML PDF covers Postman setup and a six-row table, and the CCNA Automation Workbook adds JSON, XML and YAML parsing and RESTCONF labs.

Download the PDF with the form on this page, then try the table and the mistakes list on your own data.

Frequently asked questions

Which is better, XML or JSON?
Neither wins everywhere. JSON is the better default for REST APIs and for web and mobile apps because it carries less markup around the data. XML is the better fit when the protocol requires it, as SOAP and NETCONF do, or when you need strict validation with an XSD and namespaces. REST itself doesn't force a data format.
Is XML obsolete?
No. XML is no longer the default for new web APIs, but it's still the format underneath SOAP, NETCONF (RFC 6241), SVG images and RSS feeds, and many enterprise systems still exchange it. If you accept XML from outside your network, disable DTD processing and external entities in the parser to avoid XXE injection, as OWASP advises.
What is JSON and why is it used?
JSON (JavaScript Object Notation) is a lightweight text format for structured data, defined in RFC 8259. It's used to exchange data between applications, mostly through REST APIs and in web and mobile apps. It's short to read and write, and JavaScript turns a JSON string into an object with JSON.parse().
What does XML stand for?
XML stands for Extensible Markup Language. "Extensible" means you choose your own tag names instead of using a fixed set like HTML. The W3C publishes the XML 1.0 specification.
Is a JSON file an XML file?
No. Both are plain-text data formats, but JSON uses braces, brackets and key-value pairs while XML uses nested tags, so a parser for one can't read the other. You can convert between them, but the structures don't always map one to one. XML attributes and namespaces have no direct JSON equivalent.
Can you convert XML to JSON, and JSON to XML?
Yes, with a library or an online converter. The result needs rules for what the other format lacks: XML attributes, namespaces and comments have no JSON equivalent, and XML lists are just repeated elements, so a converter has to decide when to make an array. Check the output before you rely on it.
Is YAML the same as JSON?
No, but they're close. YAML 1.2 was designed as a superset of JSON, so almost any JSON file is also valid YAML. YAML uses indentation instead of braces, allows # comments and is easier to read, which is why Ansible and Docker Compose use it. JSON has no comment syntax, and YAML doesn't allow tabs for indentation.
Is XML a coding language?
No. XML is a markup language: it describes and stores data with tags, but it has no loops or functions like Python or Java. Programs read and write XML, as in SOAP messages and NETCONF.
Which format do NETCONF and RESTCONF use?
NETCONF uses XML only, usually over SSH on TCP port 830. RESTCONF runs over HTTPS and supports both formats: the client asks for JSON with Accept: application/yang-data+json or for XML with Accept: application/yang-data+xml (RFC 8040).

Questions about this PDF

No questions yet. Ask the first one.

Ask a question

Your email address won't be published. We review every question before it appears. How we handle your data. Required fields are marked

Reviewed by

CCDE/CCIE

How to cite this resource

SMEnode Labs (2026). JSON vs XML: What's the Difference?. SMEnode Labs. https://smenode-labs.com/free-pdf/networking/json-vs-xml/

APA

SMEnode Labs. (2026). JSON vs XML: What's the Difference?. SMEnode Labs. https://smenode-labs.com/free-pdf/networking/json-vs-xml/

BibTeX

@misc{smenodelabs2026,
  title = {JSON vs XML: What's the Difference?},
  author = {{SMEnode Labs}},
  year = {2026},
  url = {https://smenode-labs.com/free-pdf/networking/json-vs-xml/},
  note = {SMEnode Labs}
}