Skip to content

πŸ” A fully custom JSON parser written in PHP from scratch β€” built to understand how parsing works under the hood without relying on json_decode()

License

Notifications You must be signed in to change notification settings

DanielHemmati/json-parser-in-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

41 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Json parser in mighty php

JSON Parser Banner

Overview

A simple JSON parser implementation in PHP that parses JSON strings into PHP data structures. This project demonstrates how to build a JSON parser from scratch without relying on PHP's built-in json_decode() function.

If you like to build your own JSON parser and you need to understand how it works, this project is for you.

Features

  • βœ… Complete JSON compliance - Passes the official JSON.org test suite
  • βœ… Full data type support:
    • Strings with escape sequences (\", \\, \/, \b, \f, \n, \r, \t)
    • Numbers (integers, floats, scientific notation: 1e3, 5.5e-1)
    • Booleans (true/false)
    • null values
    • Arrays (nested and empty)
    • Objects (nested and empty)
  • βœ… Advanced string parsing:
    • Unicode escape sequences (\uXXXX)
    • Control character validation (prevents unescaped control chars)
  • βœ… Robust number validation:
    • Prevents invalid leading zeros (e.g., 013)
    • Supports scientific notation (1e3, 2e+00, 5.5e-1)
    • Handles negative numbers and decimals

Installation

Prerequisites

  • PHP 8.4+
  • Composer

Local Setup

  1. Clone the repository:
git clone https://github.com/DanielHemmati/json-parser-in-php
cd json-parser-in-php
  1. Install dependencies:
composer install
  1. Run the tests:
./vendor/bin/pest

Contributing

Contributions are welcome! Please feel free to submit a pull request.

Todos

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

πŸ” A fully custom JSON parser written in PHP from scratch β€” built to understand how parsing works under the hood without relying on json_decode()

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages