danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON

Home Page:https://danielaparker.github.io/jsoncons

Repository from Github https://github.comdanielaparker/jsonconsRepository from Github https://github.comdanielaparker/jsoncons

uniqueItems validator throws exception in attempt to compare double and non-numerical string

sbrandprog opened this issue · comments

Describe the bug

I encountered this bug while using json-schema validator.

Validation of uniqueness of array elements fails with exception(Convert string to double failed) for objects, which contain same key, but different value types.

Seems like validator tries to convert string to double, because it wants to compare that string to a double value.

Enumerate the steps to reproduce the bug

Validate specific instance with specific schema. See example below.

Include a small, self-contained example if possible

#include <jsoncons_ext/jsonschema/jsonschema.hpp>

const char * schema_str = R"raw(
{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"type": "array",
	"uniqueItems": true,
	"items": {
		"type": "object",
		"properties": {
			"default": {
				"type": [ "string", "number" ]
			}
		}
	}
}
)raw";

const char * instance_str = R"raw(
[
	{
		"default": 200.02
	},
	{
		"default": "str"
	}
]
)raw";

int main() {
	auto instance = jsoncons::json::parse(instance_str);
	auto schema = jsoncons::jsonschema::make_json_schema(jsoncons::json::parse(schema_str));

	schema.validate(instance);

	return 0;
}

What compiler, architecture, and operating system?

  • Compiler: gcc version 14.2.1 20240910 (GCC)
  • Architecture (e.g. x86, x64): x86_64
  • Operating system: Arch Linux

What jsoncons library version?

  • Latest release 0.178.0
  • Other release ______
  • master

Thanks for reporting this, fixed on master.

Issue resolved. Thanks!