2 ms·
JSON doesn't need an API because it's a subset of Javacript: const foo = { bar: n, children = users.map(({name, id}) => ({name, id}); } foo.x = 4
by atombender 8y ago
JSON doesn't need an API because it's a subset of Javacript:
const foo = {
bar: n,
children = users.map(({name, id}) => ({name, id});
}
foo.x = 42;
DOM:
const foo = document.createElement("root");
foo.setAttribute("bar", `${n}`);
for (const ({name, id)} of children) {
const child = document.createElement("child");
child.setAttribute("name", name);
child.setAttribute("id", id);
foo.appendChild(child);
}
foo.setAttribute("x", `${42}`);
Querying with jq isn't an "API".
JSON and XML are both encodings of two different formal data models. The difference is that JSON is native to JS. XML requires an API to build a safe and valid document. There are simplifying wrappers around the DOM, but they'd be yet another API on top of an API.
Also note how XML is string-based. In order to get any type safety at all you have to use XML Schema, which only works with a data consumer that also knows XML Schema. So given <foo x="1"/>, there's no way to tell arbitary consumers that x is, in fact, a number.
There are undoubtedly toolchains that do higher-level manipulation of XML data so that you can serialize and deserialize rich, type-safe data, but the fact remains that you need such a toolchain, in every single language that is to deal with this data.