# Parser

> A program that reads text and finds how its parts fit.

**Field:** Software Development  
**Category:** Compilers & Runtimes  
**Also known as:** Parsing, Code Parser

## Think of it like

Think of it like a teacher reading a sentence. They check each word fits the rules of grammar.

## Definition

A parser is a program that reads text and works out its structure. It checks that the text follows the rules of its language. If it does, the parser turns it into a shape the program can use, often a tree. If not, it stops with an error, which is where a syntax error comes from. Compilers, browsers and JSON readers all start with a parser.

## Example

Lucy's app gets a line of JSON text from a server. JSON.parse reads it and hands back an object. Now she can ask for its age field.

## Example code

```console
$ node -e 'console.log(JSON.parse("{\"name\":\"Emma\",\"age\":9}").age)'
9
```

The parser turns plain text into an object, so the age can be read.

## Why it matters

All code and all data files go through a parser first. Nothing else can happen before that.

## Common mistake

Trying to read a structured format, like HTML or JSON, with your own text search. Use a real parser instead.

## Three principles

- **Text in.** Plain characters, one after another.
- **Structure out.** Often a tree.
- **Grammar check.** Bad input stops here.

## Related terms

- [Abstract Syntax Tree (AST)](https://learn.benibix.com/term/development/abstract-syntax-tree)
- [Syntax Error](https://learn.benibix.com/term/development/syntax-error)
- [Compiler](https://learn.benibix.com/term/development/compiler)
- [JavaScript Object Notation (JSON)](https://learn.benibix.com/term/development/json)
- [Tree-sitter](https://learn.benibix.com/term/development/tree-sitter)

---

Source: https://learn.benibix.com/term/development/parser
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
