Repository navigation
Description
You have a really nice comparison tool and we have used it to help us with improving our code. So thanks.
Please update the DynamicDataObjects library for your performance tests as the performance for duplicate slots is greatly improved to work within test cases that have a high number of fields in an object.
But the performance test you have is a bit janky. It really isn't a performance test on serializing or deserializing, but rather is a performance test that is centered around objects with a large number of fields in one object. Which is an extremely rare use-case for JSON. The problem with the test is it only tests string values so numerical value validation is never exercised, and the majority of the test is stressing performance around an object having many fields. The problem is that you are explicitly turning OFF the duplicate field searching and testing to make some of the libraries look faster, but then turning on the duplicate field searching when performing the serialization error testing to make them look testing complete. So when you compare some libraries that do properly perform duplicate field testing against other libraries that have that check turned off, you are getting great performance results for some libraries that are actually not performing the duplicate field checking. This is an issue for both generating and loading. The test should be a big file test, but not where you have thousands of fields with slightly different names because that is a non-realistic test case.
At least have all the libraries properly perform the duplicate field checking when doing the performance test. For the Generating and for the Loading tests, duplicate field checks should always be enabled for all libraries so they can properly be compared with each other. For example, in the McJson performance test, you have the following call:
procedure TMcJsonItem.fSetAsJSON(aValue: string);
begin
if (Self = nil) then Error(SItemNil, 'set as JSON');
// speed up = no key duplication verification (default)
Self.parse(aValue, True);
end;
Passing in "True" for the .Parse() call means that it is skipping duplicate field checking. Of course it will be faster than others that do properly do the check. Knowledge is freedom.
Activity
hydrobyte commentedon Jun 6, 2026
Hi Sean,
Thank you for your contact and suggestions.
I will update the version of
Dynamic Data Objectsand its tests into the next release. Please wait a moment, as I need to resolve the issue of the expired Delphi 12 CE license.Well, these tests were initially created for my needs.
Your criticisms are valid only for the "Generate" and "Load" sub-tests, but the reason for not checking for duplicates (as default in
McJSON) lies in the origin of my requirements, where the data came from an SQL database for records that did not have duplicates. So, I respectfully don't accept your statement of "to make some of the libraries look faster". Please remember that the purpose of myMcJSONunit is primarily focused on backward compatibility with very old versions of Delphi, C++Builder, and Lazarus. This is especially true because it only depends on TList internally.In fact, the Disclaimer makes this clear right from the start:
On the other hand, I believe the "Validation" and "Open File" tests are more relevant and aligned with your point of view, especially the latter, which loads a 1 MByte JSON file heavily based on vector data.
I believe that a skilled developer will pay more attention to these tests than to the "Speed Run".
In fact, it surprised me that the "Validation" test didn't generate as many comments among those who contacted us requesting improvements.
Knowledge (still) is freedom.
SeanSolberg commentedon Jun 6, 2026
Awesome. Thanks for the comments. I super appreciate your efforts. By the way, love the validation tests. I would suggest adding one that contains duplicate field names.
hydrobyte commentedon Jun 6, 2026
Sean,
Duplicated field names do not fit validation tests.
Check
{"a":1, "a":2}withjsonlint.comfor example. Its is valid and the duplication is shown as a warning:But I´ll include this as a matter of checking how Libs deal with duplication.
SeanSolberg commentedon Jun 6, 2026
Agreed. Some libraries will accept the second value and some will produce an error or warning and not allow the second value. Both of these seem like an appropriate handling. However, for the libraries that skip the checking during a parsing operation, they internally simply add another second item to their internal object value container (such as TList like you mentioned) and then within the code that uses that parsed JSON structure, the receiver is none to the wiser that they probably cannot access the second value or even that it exists. Then, if it is re-serialized out to JSON, the duplicate field is probably re-written. It's pretty important for all libraries to properly check for the potential duplicates, both to explicitly handle parsing them and to prevent producing them.
IETF RFC 8259 (The Internet Standard)
The RFC is explicit about duplicate keys. It states that keys should be unique, and warns that duplicate keys cause unpredictable behavior across different programming languages.
From Section 4 (Objects): "The names within an object SHOULD be unique."
"An object whose names are not unique is causing interoperability problems in that software receiving such an object may perform differently or unpredictably..."
hydrobyte commentedon Jun 7, 2026
Sean,
I think you've pointed out the correct angle from which to discuss this issue of duplication: the standard.
In defense of my work with
McJSON, it's worth highlighting that my library identifies duplicates as errors. Therefore, the optimization flag of not checking for duplicates is in accordance with your reasoning and also with IETF RFC 8259. For more details, search for "duplicate" in theMcJSON's test project.I also believe we're unnecessarily focusing on testing for duplicates in this situation, in reference to the "Speed Run" test. Since your goal is to improve your library, especially considering the aspects of the tests I created, let's focus more on the "Validation" and "Open File" tests. Is that alright with you?
I'm updating your library and will run new tests to update the
TestJSONproject.After updating your library and its respective tests, I will add a duplication sub-test to the "Validation" and re-evaluate all libraries in this regard. I should add that, since
McJSONidentifies these cases as errors, I believe it's on the user's side, which should actually be alerted to this type of problem.hydrobyte commentedon Jun 7, 2026
Sean,
Please check the latest commit made today. Your library has seen considerable improvements, but there are still some important points:
SeanSolberg commentedon Jun 8, 2026
Wow, your banging on code over the weekend. Dedication.
One of the things we improved 6 months ago or so was the concept of being able to choose some of the parsing rules to either be holding tight to the JSON serializing spec or to allow some freedom to parse and handle some cases that are not perfectly compliant but are still reasonable to parse. These serialization settings are in the TJsonStreamer object. The defaults are set up to allow flexibility such as allowing single quotes, parsing symbols, parsing extended types, etc.
If the tester should be as tight as possible on the rules, then we should modify the .Check call to turn those flexibilities off.
After turning off those serialization settings, the only rule failure should be #18. But we have to support stacking multiple sequential JSON serializations in series within a tstream and a string, so this is one rule we will probably never make strictly enforced.
The "Open file" test relies on "toString" which is intentionally not implemented. This library is not specific to JSON serializing because it supports many different serializers. So the concept of "ToString" could be JSON formatted or formatted to other serializations. There is, however, a "PrintToString" which is NOT JSON, but rather a json-ish format that is really for debug printing, which we probably should map to the default TObject.ToString method so something is implemented. The core TDataObject supports data types that are not natively possible in JSON such as binary data, etc, which are published in this PrintToString method. It would be pretty easy to add this test support with the following code. Notice the three options, two of which are JSON formatted:
SeanSolberg commentedon Jun 8, 2026
One other little thing since we are banging on details. For the Fail19 test, it seems that the test JSON doesn't match the description of the test case. The "Each opening bracket must be closed" is a good test, but the actual test JSON is that there is an additional character after the close of the root element. The final "]" should be moved to be a leading "[" to match the description of the actual test situation.
should be...
hydrobyte commentedon Jun 8, 2026
Sean,
Great, I think we can clear up these issues now.
Please just wait for the next commit where I will add the "Duplicated keys" tests. They will appear in the "Validation" section, but I created an extra category because the existing SHOULD in the Standard does not allow for a definitive answer about what is or is not wrong.
Next, I'll take your comments from here and apply them to
TLibDynamicDataObjects.hydrobyte commentedon Jun 9, 2026
Sean,
Please check commit
6a0f4bb.I always run all the tests and we got new results for the
Speed Run. I believe that in the previous commit, MS Defender was using the processors on this Windows 10 machine where I perform the tests.hydrobyte commentedon Jun 9, 2026
In the next commit I´ll improve these tests:
fail19.jsonfail24.jsonSeanSolberg commentedon Jun 9, 2026
Cool. But, I think the "Each closing bracket must be opened" concept is probably the same as the "Nothing but whitespace can follow the root value" rule. Because, once we hit the first "]", it is closing the root element that was started with "[". Any other location within nested JSON that runs into a "]" that wasn't opened with with a "[" will generate some kind of other parsing error I would think.
hydrobyte commentedon Jun 9, 2026
Sean,
Right, but I think these tests improvements check this.
The idea is to get the error, even the description isn't the same as the text file.
SeanSolberg commentedon Jun 9, 2026
Ahhh, yes, that makes sense.
hydrobyte commentedon Jun 9, 2026
Sean,
I'll leave this issue open for a while longer in case you want to change something in
TLibDynamicDataObjects.Right now I'm working on compiling the project for C++Builder 12.3 (Pro) and updating the tests for 32-bit C++.
The next commits will focus on this, so they shouldn't interfere with the changes we've made in the last few days.