Formatting data for an API JSON response











up vote
0
down vote

favorite












I have a couple of questions about formating data ready for an API JSON response.





  1. If sending a datetime value (YYYY-MM-DD HH:MM:SS format) in an API json response, if there is no datetime set, which one of these should it be:



    an empty string ""



    A string of "0000-00-00 00:00:00"



    null



  2. Is it good practice to make all values have a fixed datatype (not a mixed data type) in API responses? So for example, if a value will be an array, but there are no elements in the array, should the value be made an empty array rather than false or null so that value will always be an array?











share|improve this question




























    up vote
    0
    down vote

    favorite












    I have a couple of questions about formating data ready for an API JSON response.





    1. If sending a datetime value (YYYY-MM-DD HH:MM:SS format) in an API json response, if there is no datetime set, which one of these should it be:



      an empty string ""



      A string of "0000-00-00 00:00:00"



      null



    2. Is it good practice to make all values have a fixed datatype (not a mixed data type) in API responses? So for example, if a value will be an array, but there are no elements in the array, should the value be made an empty array rather than false or null so that value will always be an array?











    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a couple of questions about formating data ready for an API JSON response.





      1. If sending a datetime value (YYYY-MM-DD HH:MM:SS format) in an API json response, if there is no datetime set, which one of these should it be:



        an empty string ""



        A string of "0000-00-00 00:00:00"



        null



      2. Is it good practice to make all values have a fixed datatype (not a mixed data type) in API responses? So for example, if a value will be an array, but there are no elements in the array, should the value be made an empty array rather than false or null so that value will always be an array?











      share|improve this question















      I have a couple of questions about formating data ready for an API JSON response.





      1. If sending a datetime value (YYYY-MM-DD HH:MM:SS format) in an API json response, if there is no datetime set, which one of these should it be:



        an empty string ""



        A string of "0000-00-00 00:00:00"



        null



      2. Is it good practice to make all values have a fixed datatype (not a mixed data type) in API responses? So for example, if a value will be an array, but there are no elements in the array, should the value be made an empty array rather than false or null so that value will always be an array?








      json-api






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 10:04

























      asked Nov 7 at 9:25









      Andy

      54




      54
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote














          1. you can use null data type

          2. You can use a nullable datatype e.g. DateTime? MyNullableDate;






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186590%2fformatting-data-for-an-api-json-response%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote














            1. you can use null data type

            2. You can use a nullable datatype e.g. DateTime? MyNullableDate;






            share|improve this answer



























              up vote
              0
              down vote














              1. you can use null data type

              2. You can use a nullable datatype e.g. DateTime? MyNullableDate;






              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote










                1. you can use null data type

                2. You can use a nullable datatype e.g. DateTime? MyNullableDate;






                share|improve this answer















                1. you can use null data type

                2. You can use a nullable datatype e.g. DateTime? MyNullableDate;







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 7 at 10:25









                JJJ

                29k147591




                29k147591










                answered Nov 7 at 9:35









                Debabrata

                4618




                4618






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186590%2fformatting-data-for-an-api-json-response%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()