https://github.com/janchy2/json-expression-parser-cpp
A C++ console application that allows evaluating expressions on a JSON file.
https://github.com/janchy2/json-expression-parser-cpp
cpp json parser tokenizer
Last synced: 2 months ago
JSON representation
A C++ console application that allows evaluating expressions on a JSON file.
- Host: GitHub
- URL: https://github.com/janchy2/json-expression-parser-cpp
- Owner: janchy2
- Created: 2024-11-03T19:27:12.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-03T19:48:08.000Z (over 1 year ago)
- Last Synced: 2025-04-12T14:46:56.019Z (about 1 year ago)
- Topics: cpp, json, parser, tokenizer
- Language: C++
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
A **C++** console application that allows evaluating expressions on a **JSON** file.
Example of usage:
- test.json is a JSON file with the content:
{"a": { "b": [ 1, 2, { "c": "test" }, [11, 12] ]}}
- ./json_eval is the console application
The application supports:
- Trivial expressions with JSON paths:
$ ./json_eval test.json "a.b[1]"
2
$ ./json_eval test.json "a.b[2].c"
test
$ ./json_eval test.json "a.b"
[ 1, 2, { "c": "test" } ]
- Expressions in the subscript operator []:
$ ./json_eval test.json "a.b[a.b[1]].c"
test
- Intrinsic functions: min, max, avg, sum, size:
min, max, avg and sum return the min, max element, avg of or sum of elements from the passed array or arguments.
$ ./json_eval test.json "max(a.b[0], a.b[1])"
2
$ ./json_eval test.json "min(a.b[3])"
11
size - returns size of the passed object, array or string
$ ./json_eval test.json "size(a)"
1
$ ./json_eval test.json "size(a.b)"
4
$ ./json_eval test.json "size(a.b[a.b[1]].c)"
4
- Number literals:
$ ./json_eval test.json "max(a.b[0], 10, a.b[1], 15)"
15
- Arithmetic binary operators: +, -, *, /:
$ ./json_eval test.json "a.b[0] + a.b[1]"
3
The application uses async tasks to speed up the evaluation of operator expressions.