Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.9] - 2026-10-29

### Added
- Line and column numbers for all the parse messages, (see https://github.com/FFMG/tinyjson/issues/51). The numbers are 1-based, `'\n'`, `'\r\n'` and a lone `'\r'` each count as a single new line, and `-1, -1` is given when there is no position (e.g. null source, file could not be opened, key not found).
- `TJParseException::line()` and `TJParseException::column()` give the position of the parse error.
- The duplicate key `trace` message now gives the position of the duplicate key.

### Changed
- Incremented version to 0.2.9.
- **Breaking Change**: The `parse_options::callback_function` signature is now `std::function<void(message_type, const TJCHAR*, int line, int column)>`, existing callbacks need the two extra `int` parameters.
- The "We found a value but we expected a comma." error now points to the start of the unexpected value.

## [0.2.8] - 2026-10-15

### Added
Expand Down
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/FFMG/TinyJSON/actions/workflows/c-cpp.yml/badge.svg)](https://github.com/FFMG/TinyJSON/actions/workflows/c-cpp.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Version](https://img.shields.io/badge/version-0.2.8-blue.svg)](src/TinyJSON.h)
[![Version](https://img.shields.io/badge/version-0.2.9-blue.svg)](src/TinyJSON.h)

A lightweight and lightning-fast C++ JSON & JSON5 parser designed for high performance and minimal footprint.

Expand Down Expand Up @@ -131,8 +131,8 @@ The version is set in the `TinyJSON.h` file.
```cpp
static const short TJ_VERSION_MAJOR = 0;
static const short TJ_VERSION_MINOR = 2;
static const short TJ_VERSION_PATCH = 8;
static const char TJ_VERSION_STRING[] = "0.2.8";
static const short TJ_VERSION_PATCH = 9;
static const char TJ_VERSION_STRING[] = "0.2.9";
```

### Simple Value Access
Expand Down Expand Up @@ -167,8 +167,12 @@ if (tj) {
* rfc7159
* rfc8259
* json5_1_0_0
* Callback: (`callback_function:std::function<void(message_type, const TJCHAR*)>`) Callback function called where there is an error, warning etc.
* Callback: (`callback_function:std::function<void(message_type, const TJCHAR*, int line, int column)>`) Callback function called where there is an error, warning etc.
NB: The Callback function is called even if Throw is false.
* `line` and `column` are 1-based and point to where in the source the message was raised, (the first character is line 1, column 1).
* `'\n'`, `'\r\n'` and a lone `'\r'` each count as a single new line, a new line resets the column to 1.
* The column counts `TJCHAR` code units, so a multi-byte utf-8 character counts as more than one column. A utf-8 BOM is not counted.
* If there is no position, (the source is null, the file could not be opened, a key was not found, a value could not be converted etc.), both `line` and `column` are `-1`.
* If a getter method (`try_get_string`, `get_*(..)`, or `get<>(..)`) is called on a key that does not exist in a `TJValueObject`, a warning message indicating the missing key (e.g. `"The key 'missing' was not found!"`) is passed to the callback function.
* trace
* debug
Expand All @@ -183,18 +187,21 @@ For example ...
TinyJSON::parse_options options = {};
options.throw_exception = true;
options.max_depth = 10;
options.Callback = [&](TinyJSON::parse_options::message_type message_type, const TJCHAR* exception_message) {
options.callback_function = [&](TinyJSON::parse_options::message_type message_type, const TJCHAR* exception_message, int line, int column) {
// something, something ...
// line == 2, column == 3 for the example below.
};

try
{
auto blah = TinyJSON::TJ::parse("[0123]", options)
auto blah = TinyJSON::TJ::parse("[\n 0123]", options)
...
}
catch(TinyJSON::TJParseException ex)
{
ex.what(); // Numbers cannot have leading zeros
ex.what(); // Numbers cannot have leading zeros
ex.line(); // 2
ex.column(); // 3
}
```

Expand Down Expand Up @@ -237,6 +244,7 @@ catch(TinyJSON::TJParseException ex)
#### Parsing Exception

The parsing exception is `TinyJSON::TJParseException` and can be made optional in the `TinyJSON::parse_options` flag.
The exception also has the 1-based `line()` and `column()` of where the error happened, (both are `-1` if there is no position).

```cpp
TinyJSON::parse_options options = {};
Expand All @@ -248,7 +256,9 @@ The parsing exception is `TinyJSON::TJParseException` and can be made optional i
}
catch(TinyJSON::TJParseException ex)
{
ex.what(); // Numbers cannot have leading zeros
ex.what(); // Numbers cannot have leading zeros
ex.line(); // 1
ex.column(); // 2
}
```

Expand Down Expand Up @@ -775,7 +785,7 @@ include(FetchContent)
FetchContent_Declare(
TinyJSON
GIT_REPOSITORY https://github.com/FFMG/TinyJSON.git
GIT_TAG v0.2.8 # or main
GIT_TAG v0.2.9 # or main
)
FetchContent_MakeAvailable(TinyJSON)
target_link_libraries(your_target PUBLIC TinyJSON)
Expand Down
Loading
Loading