In model-driven network programmability, how do YANG, NETCONF, RESTCONF, XML and JSON fit together?
They are layers of one stack: YANG defines what the data is, NETCONF or RESTCONF defines how you reach and change it, and XML or JSON is the encoding the data travels in.
* One model, two protocols, two encodings: the same severity leaf can travel as XML or JSON. *
The names are easy to mix up because they always appear together, but each answers a different question:
| Layer | Question it answers | Options |
|---|---|---|
| Data model | What can be configured or read, with which types and structure? | YANG |
| Protocol | How do I read, change, validate and commit that data? | NETCONF (XML RPCs over SSH) or RESTCONF (HTTP methods over HTTPS) |
| Encoding | How is one concrete piece of data written down on the wire? | XML (NETCONF, RESTCONF) or JSON (RESTCONF) |
Because the model sits underneath both protocols, they are interchangeable views of the same data. On a Cisco IOS XE router, interfaces/interface[name]/enabled is the same YANG leaf whether you fetch it with a NETCONF <get-config> or a RESTCONF GET, and whether it comes back as XML or JSON. That is the whole advantage over the CLI: the contract (the model) stays fixed, while tools pick whichever protocol and format suit them.
Tip: Model, method, format. YANG is the model, NETCONF/RESTCONF the method, XML/JSON the format.
Go deeper:
RFC 7951 — JSON Encoding of Data Modeled with YANG — how one YANG tree is written as JSON instead of XML.
YANG — Wikipedia — the modelling language and the protocols that carry it.