Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 39 ยท Getting Started

Tools for Working with Data Formats

A practical tour of the tools for data formats: editors and linters, command-line helpers like jq and xmllint, parser libraries by language, and how to build your own mini tools.

Good tooling turns fiddly text files into something you can inspect, validate and transform in seconds. This lesson surveys what is available and then builds two small tools of your own, so you know what the big ones do under the hood.

Editors and linters

Almost every code editor can validate and format JSON, XML and YAML as you type. Look for:

  • Syntax highlighting and folding for nested structures.
  • Live validation with red squiggles on a missing comma or unclosed tag.
  • Schema support: editors such as VS Code can associate a JSON Schema or XSD with a file and offer autocomplete from it.
  • Formatters such as Prettier (JSON, YAML, Markdown) and xmllint --format (XML), so teams never argue about indentation.
  • Linters: yamllint for YAML, markdownlint for Markdown, jsonlint and taplo for TOML.

Command-line tools

The terminal is the fastest place to poke at data. These tools are read-only here (the site cannot run them), but you will use them constantly.

Terminal
# Pretty-print and query JSON
curl -s https://api.example.com/users | jq '.[] | {id, name}'

# Validate and format XML, and run an XPath query
xmllint --format feed.xml
xmllint --xpath '//item/title/text()' feed.xml

# Convert YAML to JSON with yq
yq -o=json '.' config.yml

# Lint Markdown
markdownlint README.md

jq deserves special mention. It reads JSON on standard input, applies a small filter language and prints JSON. A filter like .items[] | select(.price > 10) | .name is the JSON equivalent of an SQL query. yq offers the same ideas for YAML, TOML and XML.

Libraries by language

Every mainstream language has a parser for each format. Names to know:

Format JavaScript Python Java PHP
JSON built-in JSON json Jackson, Gson json_decode
XML DOMParser, fast-xml-parser xml.etree, lxml JAXP, JAXB SimpleXML, DOM
YAML yaml package PyYAML, ruamel SnakeYAML symfony/yaml
TOML smol-toml tomllib (3.11+) toml4j yosymfony/toml
Markdown markdown-it, marked markdown, mistune commonmark-java league/commonmark

JSON is the only one built into JavaScript. In the browser you also get DOMParser for XML. On the Node runner used by this course, none of the others exist, which is why the lessons ship short stand-ins. Stand-ins are teaching aids, not replacements: always use a maintained library in real code.

Build a mini JSON formatter

Formatting is just parsing followed by serializing with indentation. The third argument of JSON.stringify sets the indent.

Node.js A tiny JSON formatter and minifier

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Build a mini query tool

A path language such as jq's .a.b[0] is small to build. The function below follows a dotted path with optional array indexes, a stand-in for what JSONPath and jq do far more powerfully.

Node.js A miniature path query

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Online validators and playgrounds

Browser-based tools are handy for quick checks: JSON and YAML validators, XPath testers, Markdown previews and JSON Schema validators. Treat them with care: never paste secrets or personal data into a site you do not control, because you are sending that data to a server.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Which command-line tool filters and transforms JSON?

    jq reads JSON and applies a filter language to it.
  2. 2. What does the third argument of JSON.stringify control?

    Numbers (up to 10) or a string set the indent for pretty printing.
  3. 3. Why should you avoid pasting secrets into online validators?

    Online tools process your input on a server you do not control, so sensitive data may leak.

Summary

  • Editors, linters and formatters catch most syntax errors before runtime.
  • jq, yq, xmllint and friends let you query and convert data in the terminal.
  • Every language has parsers for each format; in JavaScript only JSON is built in.
  • Small mini tools show what real tools do, but use maintained libraries in production.

Next: JSON syntax