Questions tagged [jsonbuilder]

78 questions
15
votes
3 answers

How to construct json using JsonBuilder with key having the name of a variable and value having its value?

How to construct json using JsonBuilder with key and value having same name? import groovy.json.JsonBuilder def userId = 12 // some user id obtained from else where. def json = new JsonBuilder() def root = json { userId userId } print…
user235273
15
votes
3 answers

How to use groovy builder to generate an array-type json?

We can generate an object-type json by groovy's json builder: def builder = new groovy.json.JsonBuilder() def root = builder.people { person { firstName 'Guillame' lastName 'Laforge' // Named arguments are valid values…
Freewind
  • 193,756
  • 157
  • 432
  • 708
12
votes
1 answer

modifying json with jsonbuilder in Groovy

I am trying to modify content of json and then print it to see if it has changed with this code but getting error def builder = new JsonBuilder(request) log.info(builder.content) builder.content.device.dpidsha1= 'abcd' …
user1207289
  • 3,060
  • 6
  • 30
  • 66
11
votes
3 answers

Groovy Simple JSON array builder

I need to build a simple JSON array in JSON but in the loop it overwrites the first value during every iteration. def jsonBuilder = new groovy.json.JsonBuilder() contact.each { jsonBuilder.contact( FirstName: …
user2093576
  • 3,082
  • 7
  • 32
  • 43
11
votes
1 answer

How do I use groovy jsonbuilder with .each to create an array?

I would like to create an array with JSON-Builder. Expected format: { "Header": { "SomeKey" : "SomeValue" } "Data": [ { "SomeKey" : "SomeValue" }, { "SomeKey" : "SomeValue" } ] } My Code: def builder =…
Fels
  • 1,214
  • 2
  • 13
  • 27
5
votes
2 answers

How to create an array with a JsonBuilder in groovy

I would like to use closure way to make following json: { "root": [ { "key": "testkey", "value": "testvalue" } ] } I'm using following syntax: new JsonBuilder().root { 'key'(testKey) …
pixel
  • 24,905
  • 36
  • 149
  • 251
5
votes
1 answer

Caught: java.lang.StackOverflowError JsonBuilder closure

I've been trying to read an xml file and convert it to json using groovy's JsonBuilder. The problem is that when I print with def builder = new JsonBuilder(jsonObject) println builder.toPrettyString() I got a Caught:…
Francisco R
  • 53
  • 1
  • 5
5
votes
4 answers

Exclude null values using JSONBuilder in Groovy

Is it possible to create JSON values in Groovy using the default JsonBuilder library to exclude all the null values of an object? Such as what Jackson does in Java by annotating classes to exclude null values. An example would be: { "userId":…
Peymankh
  • 1,976
  • 25
  • 30
4
votes
3 answers

Unit testing rendered Json with JsonBuilder in Grails

Let's say I have a simple action in my controller that ends with: render(contentType: "text/json") { message = 'some text' foo = 'bar' } It renders correctly, as per the JSON builder documentation. However, when I attempt to unit test that…
Igor
  • 33,276
  • 14
  • 79
  • 112
4
votes
0 answers

RABL vs Json Builder

As part of a team, we are building an RoR application completely driven through API's. We already have a web app, its just that we now want to make it completely API driven. We initially kicked off with using RABL Templating Engine for generating…
boddhisattva
  • 6,908
  • 11
  • 48
  • 72
4
votes
1 answer

Why do I get a StackoverflowError on when Groovy JsonBuilder tries to serialize an Expando?

I am getting a StackoverflowError (not traced back to my code) when I try to serialize an Expando. Reproduced with groovy shell: ... groovy-2.0.6/bin/groovysh new groovy.json.JsonBuilder(new Expando(name:'hello')).toString() FATAL:…
Andy Hebert
  • 413
  • 4
  • 12
3
votes
2 answers

Groovy's JsonBuilder creates two additional attributes

JSON Object created has two additional attributes: contentHash originalClassName They are getting added automatically, which I do not want. PFB the code class Info{ def summary def description } class Simple{ def start def finish …
Rahul
  • 39
  • 3
3
votes
1 answer

Groovy - Constructing json from String

I'm using Groovy, i've tried to create a simple function which will construct a Json object from a provided Json string, then i'm trying to print this string but unfortunate it's adding Square brackets to the output. Here's a snippet from my…
Alex Brodov
  • 3,365
  • 18
  • 43
  • 66
3
votes
1 answer

Groovy JsonBuilder strange behavior when toString()

I need to create a json to use as body in an http.request. I'm able to build dynamically up the json, but I noticed a strange behavior when calling builder.toString() twice. The resulting json was totally different. I'm likely to think this is…
Mesi Rendón
  • 851
  • 1
  • 9
  • 21
3
votes
1 answer

StackOverflowError in java_lang_Class$isArray.call() when using Groovy's JsonBuilder

My Grails application and its integration tests are throwing a StackOverflowError when I try to use Groovy's JsonBuilder class on my domain classes. My code looks like this: String result = new JsonBuilder(new MyDomainClass()) Since I found…
1
2 3 4 5 6