Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Proposal for better JSON serialization control

    Qt Contribution
    5
    7
    155
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Plastic.Jesus last edited by

      Hello all.

      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.

      Proposal:

      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.

      Regards,
      Stephen Punak
      Principal Engineer
      Lordstown Motors Corporation

      jsulm JonB 2 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Plastic.Jesus last edited by

        @Plastic-Jesus This is user forum. If you want to propose something you should create a change request in Qt bug tracker (https://bugreports.qt.io/secure/Dashboard.jspa).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • JKSH
          JKSH Moderators last edited by

          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!

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          P 1 Reply Last reply Reply Quote 2
          • JonB
            JonB @Plastic.Jesus last edited by JonB

            @Plastic-Jesus
            Can you name another toolkit/library which does offer the controls on serialization you mention? I have used various ones outside of Qt's (e.g. JavaScript, Python) and am not aware of one which does.

            P 1 Reply Last reply Reply Quote 0
            • P
              Plastic.Jesus @JonB last edited by Plastic.Jesus

              @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.

              1 Reply Last reply Reply Quote 1
              • P
                Plastic.Jesus @JKSH last edited by

                @JKSH Thanks! That's exactly what I was look for.
                Apologies for the spurious post then ;)

                1 Reply Last reply Reply Quote 0
                • Chronal
                  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.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post