Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. Qt Contribution
  4. Proposal for better JSON serialization control

Proposal for better JSON serialization control

Scheduled Pinned Locked Moved Unsolved Qt Contribution
7 Posts 5 Posters 1.1k Views
  • 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 Offline
    P Offline
    Plastic.Jesus
    wrote on last edited by
    #1

    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

    jsulmJ JonBJ 2 Replies Last reply
    0
    • P Plastic.Jesus

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        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
        2
        • P Plastic.Jesus

          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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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
          0
          • JonBJ 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 Offline
            P Offline
            Plastic.Jesus
            wrote on last edited by Plastic.Jesus
            #5

            @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
            1
            • JKSHJ JKSH

              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!

              P Offline
              P Offline
              Plastic.Jesus
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • ChronalC Offline
                ChronalC Offline
                Chronal
                wrote on last edited by
                #7

                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
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved