Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-parser

A small command-line JSON explorer with a path-based query language (jq-lite). Load a JSON file, inspect its shape, and pull out values interactively or from scripts.

Quick start

cmake -S . -B build
cmake --build build
./build/json_parser mine.json

At the json> prompt:

json> structure 2
json> players[0].player
json> players[*].player
json> help
json> exit

Usage

Interactive REPL

./json_parser path/to/file.json
  • Type a query to print matching values as JSON.
  • Type a meta-command (help, print, structure, …) for REPL actions.
  • Press Tab for autocomplete (fields, array indices, string keys).
  • Use Up/Down for history.
  • Invalid queries print an error and the REPL keeps running.

One-shot mode (-q)

Run a single query and exit — useful for scripts and pipes:

./json_parser mine.json -q 'players[0].player'
./json_parser mine.json -q 'players[*].inventory[*].item'

Exit code is non-zero if the query fails.

REPL meta-commands

Command Description
help Show query syntax and commands
print or . Dump the full loaded JSON
structure or tree Folder-tree view of the file (keys, types, counts)
structure 3 or tree 3 Same, but limit depth (handy for large files)
clear Clear the screen
exit Quit

The structure view uses colors: blue {n} for objects, green [n] for arrays, and dimmed previews for leaf values.

Query language

Queries are a chain of steps applied left to right:

Step Example Meaning
Field players Object member by name
Dot + field .player Same (dot is optional between steps)
Array index [0] Element at index
Array wildcard [*] Every element
String key ["meta"] Object member by string key

Examples (using mine.json):

players                          # the players array
players[0]                       # first player object
players[0].player                # "Steve"
players[0].location              # location object
players[0].inventory[0].item     # "Diamond Sword"
players[*].player                # all player names
players[0]["settings"].gamemode  # string-key access

Each matching value is printed as valid JSON on its own line.

Autocomplete

While typing a query, press Tab to see suggestions based on the loaded file:

  • Object fields after . or at the start of a step
  • Array indices after [
  • String keys inside ["…"]

Suggestions show type hints (e.g. players[3], inventory{8}) and colors for objects vs arrays.

Building and testing

cmake -S . -B build
cmake --build build
ctest --test-dir build

Requires C++20, CMake, and replxx (for the REPL). See CMakeLists.txt for how replxx is located.

Docker

A multi-stage Dockerfile is included for containerized builds.

Project layout

Path Role
json/ JSON scanner, parser, AST, serializer
Query/ Query scanner, parser, evaluator
cmd/ Autocomplete, structure tree
tests/ GoogleTest suite
mine.json Sample file for trying queries

About

JSON query engine in C++ — includes a full JSON parser (lexer, parser, AST) and a custom query language for extracting and filtering data.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages