How can I pretty format a JSON file, with all the correct indents and everything?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have a JSON file on CentOS where all text is on the same line. How can I pretty format it with all the correct indents and everything?







share|improve this question

















  • 1




    Could you show us an example file? Does this need to be automatic? If not, just load it in a decent text editor and do it manually (in emacs, select everything and M-X indent-selection).
    – terdon♦
    May 18 at 13:42










  • Have a look at jq. Also very handy if you want to process JSON.
    – dirkt
    May 18 at 14:43














up vote
1
down vote

favorite












I have a JSON file on CentOS where all text is on the same line. How can I pretty format it with all the correct indents and everything?







share|improve this question

















  • 1




    Could you show us an example file? Does this need to be automatic? If not, just load it in a decent text editor and do it manually (in emacs, select everything and M-X indent-selection).
    – terdon♦
    May 18 at 13:42










  • Have a look at jq. Also very handy if you want to process JSON.
    – dirkt
    May 18 at 14:43












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a JSON file on CentOS where all text is on the same line. How can I pretty format it with all the correct indents and everything?







share|improve this question













I have a JSON file on CentOS where all text is on the same line. How can I pretty format it with all the correct indents and everything?









share|improve this question












share|improve this question




share|improve this question








edited May 18 at 13:43









terdon♦

122k28226398




122k28226398









asked May 18 at 13:41









dr01

15.2k114768




15.2k114768







  • 1




    Could you show us an example file? Does this need to be automatic? If not, just load it in a decent text editor and do it manually (in emacs, select everything and M-X indent-selection).
    – terdon♦
    May 18 at 13:42










  • Have a look at jq. Also very handy if you want to process JSON.
    – dirkt
    May 18 at 14:43












  • 1




    Could you show us an example file? Does this need to be automatic? If not, just load it in a decent text editor and do it manually (in emacs, select everything and M-X indent-selection).
    – terdon♦
    May 18 at 13:42










  • Have a look at jq. Also very handy if you want to process JSON.
    – dirkt
    May 18 at 14:43







1




1




Could you show us an example file? Does this need to be automatic? If not, just load it in a decent text editor and do it manually (in emacs, select everything and M-X indent-selection).
– terdon♦
May 18 at 13:42




Could you show us an example file? Does this need to be automatic? If not, just load it in a decent text editor and do it manually (in emacs, select everything and M-X indent-selection).
– terdon♦
May 18 at 13:42












Have a look at jq. Also very handy if you want to process JSON.
– dirkt
May 18 at 14:43




Have a look at jq. Also very handy if you want to process JSON.
– dirkt
May 18 at 14:43










3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










Use the package yajl, Yet Another JSON Library. On CentOS 7 it is located in the base repo, and is most probably already installed on the machine.



To pretty-print a JSON file:



cat myfile.json | json_reformat


or simply



json_reformat < myfile.json


To verify that a file is in correct JSON syntax:



json_verify < myfile.json





share|improve this answer






























    up vote
    1
    down vote













    If you don't want to install an additional package and have python available you can do:



    python -m json.tool myfile.json


    It also supports reading from STDIN






    share|improve this answer




























      up vote
      1
      down vote













      Use jq a very good JSON processor and from personal preference, its the best available in the market



      for just pretty print, use



      jq . file_name





      share|improve this answer





















        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        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: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );








         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444610%2fhow-can-i-pretty-format-a-json-file-with-all-the-correct-indents-and-everything%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote



        accepted










        Use the package yajl, Yet Another JSON Library. On CentOS 7 it is located in the base repo, and is most probably already installed on the machine.



        To pretty-print a JSON file:



        cat myfile.json | json_reformat


        or simply



        json_reformat < myfile.json


        To verify that a file is in correct JSON syntax:



        json_verify < myfile.json





        share|improve this answer



























          up vote
          1
          down vote



          accepted










          Use the package yajl, Yet Another JSON Library. On CentOS 7 it is located in the base repo, and is most probably already installed on the machine.



          To pretty-print a JSON file:



          cat myfile.json | json_reformat


          or simply



          json_reformat < myfile.json


          To verify that a file is in correct JSON syntax:



          json_verify < myfile.json





          share|improve this answer

























            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            Use the package yajl, Yet Another JSON Library. On CentOS 7 it is located in the base repo, and is most probably already installed on the machine.



            To pretty-print a JSON file:



            cat myfile.json | json_reformat


            or simply



            json_reformat < myfile.json


            To verify that a file is in correct JSON syntax:



            json_verify < myfile.json





            share|improve this answer















            Use the package yajl, Yet Another JSON Library. On CentOS 7 it is located in the base repo, and is most probably already installed on the machine.



            To pretty-print a JSON file:



            cat myfile.json | json_reformat


            or simply



            json_reformat < myfile.json


            To verify that a file is in correct JSON syntax:



            json_verify < myfile.json






            share|improve this answer















            share|improve this answer



            share|improve this answer








            edited May 18 at 13:47


























            answered May 18 at 13:42









            dr01

            15.2k114768




            15.2k114768






















                up vote
                1
                down vote













                If you don't want to install an additional package and have python available you can do:



                python -m json.tool myfile.json


                It also supports reading from STDIN






                share|improve this answer

























                  up vote
                  1
                  down vote













                  If you don't want to install an additional package and have python available you can do:



                  python -m json.tool myfile.json


                  It also supports reading from STDIN






                  share|improve this answer























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    If you don't want to install an additional package and have python available you can do:



                    python -m json.tool myfile.json


                    It also supports reading from STDIN






                    share|improve this answer













                    If you don't want to install an additional package and have python available you can do:



                    python -m json.tool myfile.json


                    It also supports reading from STDIN







                    share|improve this answer













                    share|improve this answer



                    share|improve this answer











                    answered May 18 at 16:25









                    Dalvenjia

                    1,14648




                    1,14648




















                        up vote
                        1
                        down vote













                        Use jq a very good JSON processor and from personal preference, its the best available in the market



                        for just pretty print, use



                        jq . file_name





                        share|improve this answer

























                          up vote
                          1
                          down vote













                          Use jq a very good JSON processor and from personal preference, its the best available in the market



                          for just pretty print, use



                          jq . file_name





                          share|improve this answer























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            Use jq a very good JSON processor and from personal preference, its the best available in the market



                            for just pretty print, use



                            jq . file_name





                            share|improve this answer













                            Use jq a very good JSON processor and from personal preference, its the best available in the market



                            for just pretty print, use



                            jq . file_name






                            share|improve this answer













                            share|improve this answer



                            share|improve this answer











                            answered May 18 at 16:34









                            mkmayank

                            36310




                            36310






















                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444610%2fhow-can-i-pretty-format-a-json-file-with-all-the-correct-indents-and-everything%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Displaying single band from multi-band raster using QGIS

                                How many registers does an x86_64 CPU actually have?