Unsolved Proposal for better JSON serialization control
Been a Qt user/fan for almost two decades, and it's time to give back a little. This is my first foray into contribution.
First the problem statement:
More and more, JSON is being used for human-readable files (think almost all Visual Studio Code configuration files).
It is understood that the JSON format does not specify the order of objects serialized into output. However, for human-readable JSON, better control of object serialization order is often desirable. Related object types may be better suited to be near each other in the output.
Additionally, the order of properties in a JSON object can make a huge difference in (human) readability.
The output of objects and values produced by QJsonDocument::toJson() is serialized in alphabetical order, and there are no controls over output serialization other than Indented or Compact.
Create a QJsonSerializer class which will provide finer grained control over serialization. This would be an optional parameter to QJsonDocument::toJson().
The default QJsonSerializer would behave exactly as the current serialization, providing full backwards compatibility. However, the developer could subclass QJsonSerializer and override protected methods within to provide feedback/hints about serialization order, indentation, brace formatting and other common serialization properties.
I'd love to get some feedback on this idea. Looking around the interwebs, this feature is commonly asked about. If it would be useful, I'd be happy to implement it.
Lordstown Motors Corporation
I recommend you subscribe to the Development mailing list (https://lists.qt-project.org/listinfo/development ) and post your proposal there. Qt engineers are active on that list, and you should be able to get a decent discussion going if they are interested in your proposal.
All the best!
JonB last edited by JonB
@JonB This sort of functionality is available for sure in the .NET Json libraries (Newtonsoft), and I believe it's also available in the Java JSON libraries.
@JKSH Thanks! That's exactly what I was look for.
Apologies for the spurious post then ;)
Chronal last edited by
I think this is a great idea. It would be great to have more control over the serialization of JSON data. It would make it easier to customize the output and make sure that the data is properly formatted. It would also make it easier to debug any issues that may arise. I think this would be a great addition to the Qt library.