Best way to parse more than one json with JsonSlurperBinary Data in JSON String. Something better than Base64Parsing JSON with Unix toolsHow to parse JSON in JavaWhy can't Python parse this JSON data?Parse JSON in JavaScript?Parsing a JSON string in RubyHow to parse JSON using Node.js?Error in parsing JsonCan I do this with ExpandoMetaClasses in Groovy?Using JsonSlurper to parse MySQL Json output returns groovy.lang.MissingMethodException

Should I ask for permission to write an expository post about someone's else research?

Who are these characters/superheroes in the posters from Chris's room in Family Guy?

Am I overreacting to my team leader's unethical requests?

How does 'AND' distribute over 'OR' (Set Theory)?

Continuous vertical line using booktabs in tabularx table?

What is the difference between 型 and 形?

Can a fight scene, component-wise, be too complex and complicated?

English - Acceptable use of parentheses in an author's name

Does a code snippet compile? Or does it get compiled?

What are the conventions for transcribing Semitic languages into Greek?

function evaluation - I don't get it

Why is transplanting a specific intact brain impossible if it is generally possible?

Is it legal for a company to enter an agreement not to hire employees from another company?

What is my malfunctioning AI harvesting from humans?

Does this Foo machine halt?

Trying to write a shell script that keeps testing a server remotely, but it keeps falling in else statement when I logout

Why did Gandalf use a sword against the Balrog?

Help evaluating integral (anything simple that I am missing?)

What does Apple mean by "This may decrease battery life"?

Wherein the Shatapatha Brahmana it was mentioned about 8.64 lakh alphabets in Vedas?

Is refreshing multiple times a test case for web applications?

Withdrew when Jimmy met up with Heath

Dropdowns & Chevrons for Right to Left languages

How does "Te vas a cansar" mean "You're going to get tired"?



Best way to parse more than one json with JsonSlurper


Binary Data in JSON String. Something better than Base64Parsing JSON with Unix toolsHow to parse JSON in JavaWhy can't Python parse this JSON data?Parse JSON in JavaScript?Parsing a JSON string in RubyHow to parse JSON using Node.js?Error in parsing JsonCan I do this with ExpandoMetaClasses in Groovy?Using JsonSlurper to parse MySQL Json output returns groovy.lang.MissingMethodException






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm using Groovy JsonSlurper parsing json. I found that I should initialize a JsonSlurper instance before I call parseText() method.



  1. When I have multiple json objects (e.g. a LinkedList<String> with n json texts) to parse, should I initialize n JsonSlurper or initialize a JsonSlurper and call its parseText n times?


  2. When I use JsonSlurper on a Web Server, is that the best practice to just maintain one global JsonSlurper instance and use it everywhere? Or initialize an instance every time I receive an HTTP request?


Or to be more clear, what the constructor of JsonSlurper do?










share|improve this question






























    1















    I'm using Groovy JsonSlurper parsing json. I found that I should initialize a JsonSlurper instance before I call parseText() method.



    1. When I have multiple json objects (e.g. a LinkedList<String> with n json texts) to parse, should I initialize n JsonSlurper or initialize a JsonSlurper and call its parseText n times?


    2. When I use JsonSlurper on a Web Server, is that the best practice to just maintain one global JsonSlurper instance and use it everywhere? Or initialize an instance every time I receive an HTTP request?


    Or to be more clear, what the constructor of JsonSlurper do?










    share|improve this question


























      1












      1








      1








      I'm using Groovy JsonSlurper parsing json. I found that I should initialize a JsonSlurper instance before I call parseText() method.



      1. When I have multiple json objects (e.g. a LinkedList<String> with n json texts) to parse, should I initialize n JsonSlurper or initialize a JsonSlurper and call its parseText n times?


      2. When I use JsonSlurper on a Web Server, is that the best practice to just maintain one global JsonSlurper instance and use it everywhere? Or initialize an instance every time I receive an HTTP request?


      Or to be more clear, what the constructor of JsonSlurper do?










      share|improve this question














      I'm using Groovy JsonSlurper parsing json. I found that I should initialize a JsonSlurper instance before I call parseText() method.



      1. When I have multiple json objects (e.g. a LinkedList<String> with n json texts) to parse, should I initialize n JsonSlurper or initialize a JsonSlurper and call its parseText n times?


      2. When I use JsonSlurper on a Web Server, is that the best practice to just maintain one global JsonSlurper instance and use it everywhere? Or initialize an instance every time I receive an HTTP request?


      Or to be more clear, what the constructor of JsonSlurper do?







      json groovy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 8:35









      Huang YuhengHuang Yuheng

      3853 silver badges19 bronze badges




      3853 silver badges19 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2














          You can think of JsonSlurper as a facade for creating a concrete JSON parser implementation. For instance, the default parser that gets created anytime you invoke parse() or parseText() methods is JsonParserCharArray. If you take a look at JsonSlurper source code you will see that it encapsulates the following five private fields:



           private int maxSizeForInMemory = 2000000;
          private boolean chop = false;
          private boolean lazyChop = true;
          private boolean checkDates = true;

          private JsonParserType type = JsonParserType.CHAR_BUFFER;


          When you create JsonSlurper you use these default values, but for any specific use case, you can modify them to fit best your needs.



          Answering your first question, it does make sense to instantiate a single JsonSlurper and use to parse all Strings while iterating the list. Something like :



          def slurper = new JsonSlurper()
          def parsed = jsons.collect slurper.parseText(it)


          If your list is size 1000 let's say, it will create a single JsonSlurper object and 1000 JsonParser objects, instead of 1000 JsonSlurper objects and 1000 JsonParser objects.



          Answering your second question, there is no good context-free answer to this question. It highly depends on a few factors like the server load, JSON serialization/deserialization frequency, available memory, JsonSlurper use cases and so on. You actually have to monitor your application and experiment with both approaches to see what works better for you. For instance, if your application handles HTTP requests constantly and it constantly creates the same JsonSlurper and uses exactly the same default values, then you might consider creating a singleton-like bean that injects the same instance of JsonSlurper to handle every HTTP request. But on the other hand, if your application does not suffer from tons of parallel requests and it handles a few sequential requests on average, then keeping a JsonSlurper object in memory for all the time may sound like a wasteful resources utilization.






          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',
            autoActivateHeartbeat: false,
            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%2f55372808%2fbest-way-to-parse-more-than-one-json-with-jsonslurper%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









            2














            You can think of JsonSlurper as a facade for creating a concrete JSON parser implementation. For instance, the default parser that gets created anytime you invoke parse() or parseText() methods is JsonParserCharArray. If you take a look at JsonSlurper source code you will see that it encapsulates the following five private fields:



             private int maxSizeForInMemory = 2000000;
            private boolean chop = false;
            private boolean lazyChop = true;
            private boolean checkDates = true;

            private JsonParserType type = JsonParserType.CHAR_BUFFER;


            When you create JsonSlurper you use these default values, but for any specific use case, you can modify them to fit best your needs.



            Answering your first question, it does make sense to instantiate a single JsonSlurper and use to parse all Strings while iterating the list. Something like :



            def slurper = new JsonSlurper()
            def parsed = jsons.collect slurper.parseText(it)


            If your list is size 1000 let's say, it will create a single JsonSlurper object and 1000 JsonParser objects, instead of 1000 JsonSlurper objects and 1000 JsonParser objects.



            Answering your second question, there is no good context-free answer to this question. It highly depends on a few factors like the server load, JSON serialization/deserialization frequency, available memory, JsonSlurper use cases and so on. You actually have to monitor your application and experiment with both approaches to see what works better for you. For instance, if your application handles HTTP requests constantly and it constantly creates the same JsonSlurper and uses exactly the same default values, then you might consider creating a singleton-like bean that injects the same instance of JsonSlurper to handle every HTTP request. But on the other hand, if your application does not suffer from tons of parallel requests and it handles a few sequential requests on average, then keeping a JsonSlurper object in memory for all the time may sound like a wasteful resources utilization.






            share|improve this answer





























              2














              You can think of JsonSlurper as a facade for creating a concrete JSON parser implementation. For instance, the default parser that gets created anytime you invoke parse() or parseText() methods is JsonParserCharArray. If you take a look at JsonSlurper source code you will see that it encapsulates the following five private fields:



               private int maxSizeForInMemory = 2000000;
              private boolean chop = false;
              private boolean lazyChop = true;
              private boolean checkDates = true;

              private JsonParserType type = JsonParserType.CHAR_BUFFER;


              When you create JsonSlurper you use these default values, but for any specific use case, you can modify them to fit best your needs.



              Answering your first question, it does make sense to instantiate a single JsonSlurper and use to parse all Strings while iterating the list. Something like :



              def slurper = new JsonSlurper()
              def parsed = jsons.collect slurper.parseText(it)


              If your list is size 1000 let's say, it will create a single JsonSlurper object and 1000 JsonParser objects, instead of 1000 JsonSlurper objects and 1000 JsonParser objects.



              Answering your second question, there is no good context-free answer to this question. It highly depends on a few factors like the server load, JSON serialization/deserialization frequency, available memory, JsonSlurper use cases and so on. You actually have to monitor your application and experiment with both approaches to see what works better for you. For instance, if your application handles HTTP requests constantly and it constantly creates the same JsonSlurper and uses exactly the same default values, then you might consider creating a singleton-like bean that injects the same instance of JsonSlurper to handle every HTTP request. But on the other hand, if your application does not suffer from tons of parallel requests and it handles a few sequential requests on average, then keeping a JsonSlurper object in memory for all the time may sound like a wasteful resources utilization.






              share|improve this answer



























                2












                2








                2







                You can think of JsonSlurper as a facade for creating a concrete JSON parser implementation. For instance, the default parser that gets created anytime you invoke parse() or parseText() methods is JsonParserCharArray. If you take a look at JsonSlurper source code you will see that it encapsulates the following five private fields:



                 private int maxSizeForInMemory = 2000000;
                private boolean chop = false;
                private boolean lazyChop = true;
                private boolean checkDates = true;

                private JsonParserType type = JsonParserType.CHAR_BUFFER;


                When you create JsonSlurper you use these default values, but for any specific use case, you can modify them to fit best your needs.



                Answering your first question, it does make sense to instantiate a single JsonSlurper and use to parse all Strings while iterating the list. Something like :



                def slurper = new JsonSlurper()
                def parsed = jsons.collect slurper.parseText(it)


                If your list is size 1000 let's say, it will create a single JsonSlurper object and 1000 JsonParser objects, instead of 1000 JsonSlurper objects and 1000 JsonParser objects.



                Answering your second question, there is no good context-free answer to this question. It highly depends on a few factors like the server load, JSON serialization/deserialization frequency, available memory, JsonSlurper use cases and so on. You actually have to monitor your application and experiment with both approaches to see what works better for you. For instance, if your application handles HTTP requests constantly and it constantly creates the same JsonSlurper and uses exactly the same default values, then you might consider creating a singleton-like bean that injects the same instance of JsonSlurper to handle every HTTP request. But on the other hand, if your application does not suffer from tons of parallel requests and it handles a few sequential requests on average, then keeping a JsonSlurper object in memory for all the time may sound like a wasteful resources utilization.






                share|improve this answer













                You can think of JsonSlurper as a facade for creating a concrete JSON parser implementation. For instance, the default parser that gets created anytime you invoke parse() or parseText() methods is JsonParserCharArray. If you take a look at JsonSlurper source code you will see that it encapsulates the following five private fields:



                 private int maxSizeForInMemory = 2000000;
                private boolean chop = false;
                private boolean lazyChop = true;
                private boolean checkDates = true;

                private JsonParserType type = JsonParserType.CHAR_BUFFER;


                When you create JsonSlurper you use these default values, but for any specific use case, you can modify them to fit best your needs.



                Answering your first question, it does make sense to instantiate a single JsonSlurper and use to parse all Strings while iterating the list. Something like :



                def slurper = new JsonSlurper()
                def parsed = jsons.collect slurper.parseText(it)


                If your list is size 1000 let's say, it will create a single JsonSlurper object and 1000 JsonParser objects, instead of 1000 JsonSlurper objects and 1000 JsonParser objects.



                Answering your second question, there is no good context-free answer to this question. It highly depends on a few factors like the server load, JSON serialization/deserialization frequency, available memory, JsonSlurper use cases and so on. You actually have to monitor your application and experiment with both approaches to see what works better for you. For instance, if your application handles HTTP requests constantly and it constantly creates the same JsonSlurper and uses exactly the same default values, then you might consider creating a singleton-like bean that injects the same instance of JsonSlurper to handle every HTTP request. But on the other hand, if your application does not suffer from tons of parallel requests and it handles a few sequential requests on average, then keeping a JsonSlurper object in memory for all the time may sound like a wasteful resources utilization.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 9:09









                Szymon StepniakSzymon Stepniak

                20.9k8 gold badges40 silver badges70 bronze badges




                20.9k8 gold badges40 silver badges70 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372808%2fbest-way-to-parse-more-than-one-json-with-jsonslurper%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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현