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;
I'm using Groovy JsonSlurper
parsing json. I found that I should initialize a JsonSlurper
instance before I call parseText()
method.
When I have multiple json objects (e.g. a
LinkedList<String>
withn
json texts) to parse, should I initializen
JsonSlurper
or initialize aJsonSlurper
and call itsparseText
n
times?When I use
JsonSlurper
on a Web Server, is that the best practice to just maintain one globalJsonSlurper
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
add a comment |
I'm using Groovy JsonSlurper
parsing json. I found that I should initialize a JsonSlurper
instance before I call parseText()
method.
When I have multiple json objects (e.g. a
LinkedList<String>
withn
json texts) to parse, should I initializen
JsonSlurper
or initialize aJsonSlurper
and call itsparseText
n
times?When I use
JsonSlurper
on a Web Server, is that the best practice to just maintain one globalJsonSlurper
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
add a comment |
I'm using Groovy JsonSlurper
parsing json. I found that I should initialize a JsonSlurper
instance before I call parseText()
method.
When I have multiple json objects (e.g. a
LinkedList<String>
withn
json texts) to parse, should I initializen
JsonSlurper
or initialize aJsonSlurper
and call itsparseText
n
times?When I use
JsonSlurper
on a Web Server, is that the best practice to just maintain one globalJsonSlurper
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
I'm using Groovy JsonSlurper
parsing json. I found that I should initialize a JsonSlurper
instance before I call parseText()
method.
When I have multiple json objects (e.g. a
LinkedList<String>
withn
json texts) to parse, should I initializen
JsonSlurper
or initialize aJsonSlurper
and call itsparseText
n
times?When I use
JsonSlurper
on a Web Server, is that the best practice to just maintain one globalJsonSlurper
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
json groovy
asked Mar 27 at 8:35
Huang YuhengHuang Yuheng
3853 silver badges19 bronze badges
3853 silver badges19 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
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
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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