Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iprakharv/json-parser-python
This is a Python-based JSON parser that validates JSON objects. It checks for the correctness of the JSON format and handles multiple types of JSON structures, including strings, numbers, booleans, null values, arrays, and nested objects.
https://github.com/iprakharv/json-parser-python
json json-parser json-parsing parsing python python-3 python-script python3
Last synced: 12 days ago
JSON representation
This is a Python-based JSON parser that validates JSON objects. It checks for the correctness of the JSON format and handles multiple types of JSON structures, including strings, numbers, booleans, null values, arrays, and nested objects.
- Host: GitHub
- URL: https://github.com/iprakharv/json-parser-python
- Owner: iPrakharV
- Created: 2024-10-21T18:04:29.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2024-10-21T21:08:06.000Z (2 months ago)
- Last Synced: 2024-12-16T05:35:53.026Z (18 days ago)
- Topics: json, json-parser, json-parsing, parsing, python, python-3, python-script, python3
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON Parser
This is a Python based JSON parser that validates JSON objects. It checks for the correctness of the JSON format and handles multiple types of JSON structures, including strings, numbers, booleans, null values, arrays, and nested objects.
## Table of Contents
- [Introduction](#introduction)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Tests](#tests)## Introduction
This project helps you learn the basics of creating a simple JSON parser. The project consists of multiple steps:
- Step 1: Parsing an empty JSON object `{}`.
- Step 2: Parsing a simple key-value JSON object.
- Step 3: Parsing JSON with multiple types like strings, numbers, booleans, and null values.
- Step 4: Parsing nested objects and arrays.
- Step 5: Adding custom tests.The parser uses Python’s built-in `json` module to validate JSON structures.
## Features
- Supports basic JSON object validation
- Handles JSON types: strings, numbers, booleans, nulls
- Supports nested objects and arrays
- Provides useful error messages for invalid JSON## Installation
1. **Clone the repository**:
```bash
git clone https://github.com/iPrakharV/JSON-Parser-Python.git
cd JSON-Parser
```2. **Install Python**:
Ensure that Python 3 is installed on your machine. You can download Python [here](https://www.python.org/downloads/).## Usage
1. **Run the parser**:
The main script takes a JSON object as input and determines whether it's valid or not.```bash
python Main.py
```After running the script, you'll be prompted to enter a JSON string, for example:
```
Enter JSON data: {"key": "value"}
```2. **Output**:
The program will print either:
- `Valid JSON Object`
- `Invalid JSON Object` (with an error message if applicable)## Examples
### Example 1: Valid JSON
```json
{
"key1": true,
"key2": false,
"key3": null,
"key4": "value",
"key5": 101
}
```
This would result in:
```bash
Valid JSON Object
```### Example 2: Invalid JSON (due to improper boolean)
```json
{
"key1": true,
"key2": False, # Capitalized False is invalid in JSON
"key3": null
}
```
This would result in:
```bash
Invalid JSON Object: Expecting value: line 3 column 10 (char 24)
```
## TestsYou can run the pre-defined test cases stored in the tests/ folder. Each folder contains JSON files to test the parser against.
```bash
# Run tests for step 1
python parser.py < tests/step1/test1.json# Run tests for step 2
python parser.py < tests/step2/test1.json```