Questions tagged [jsonbuilder]

78 questions
0
votes
1 answer

Why does Date serialize for a JSON key differently than it does for a JSON value?

With the following code: def date = new Date() println new groovy.json.JsonBuilder([(date): date]).toString() The result is something like {"Fri Oct 28 15:00:45 ART 2016":"2016-10-28T18:00:45+0000"} I was expecting the same representation as key…
Fernando
  • 2,131
  • 3
  • 27
  • 46
0
votes
1 answer

Groovy define an embedded json object on an embedded json object using jsonbuilder

I want to define the following json string using jsonbuilder.. { "a":"a", "b":"b", "c":{"d":"d", "e":"e", "f":{"g":"g"} } } I can't seem to define the property f as an embedded object, this is my attempt... import…
jonesy
  • 579
  • 2
  • 7
  • 25
0
votes
1 answer

Jbuilder Rails - Verifying boolean

I need to render a JSON in Rails but before I want to verify a boolean from my class, (e.g. Stores) which have "published" boolean. I've tried something like that: json.extract! @store json.store do if @store.published true …
Gehlen
  • 160
  • 1
  • 15
0
votes
1 answer

Groovy JsonBuilder capitalising field names

I'm using the Groovy JsonBuilder to generate JSON to send over HTTP. My problem is it's capitalising some of the keys in the map it's given. I give it an object of this class: public class TestSNP { private String snpID; TestSNP(String…
kiml42
  • 638
  • 2
  • 11
  • 26
0
votes
0 answers

Groovy JsonBuilder print array of objects

I want to print json like [ {"ID" : 1, "NAME" : "test1"}, {"ID" : 2, "NAME" : "test2"} ] Is it possible with jsonbuilder?
0
votes
1 answer

Groovy JsonBuilder appending \u0000's to string

I'm trying to make a simple UDP socket server for a Unity3D game I'm making, and I've got it mostly working. I can send messages to it and read the messages. But when I'm trying to send the message back to the client (for testing purposes, at the…
Fiberwire
  • 55
  • 1
  • 8
0
votes
0 answers

StackOverflowError while creating JSON from an instance of some class using JsonBuilder

I am creating JSON from an instance of class using JsonBuilder. But I am getting StackOverflowError. I created instance of MyClass, in Grails project. class MyBook { def isbn def title def author def publisher } and the code which…
Pankaj Shinde
  • 3,361
  • 2
  • 35
  • 44
0
votes
1 answer

object in object for Json built by JsonBuilder() in Groovy

My Groovy is 2.4.0 My code: def builder2 = new JsonBuilder() builder2.book { isbn '0321774094' title 'Scala for the Impatient' author (['Cay S. Horstmann', 'Hellen']) publisher 'Addison-Wesley Professional' content99 { …
wureka
  • 731
  • 1
  • 11
  • 26
0
votes
1 answer

How to make a created JSON object an groovy object, so that I cat access properties via dot(.) operator

I created a JSON object via JSONBuilder class: def json = new JSONBuilder().build {...} How can I transform this JSON object to groovy object, so that I can access json properties via dot('.') operator? JSON object has a field - target. And I can…
Korobko Alex
  • 816
  • 1
  • 7
  • 10
0
votes
1 answer

sharing jsonbuilder files for index and show

Let's say I have a model called Customer. My index.json.jbuilder looks something like this eg json.array!(@customers) do |customer| json.extract! customer, :id, :name, :phone_number, :email # some more nested fields of customer end and my…
Vishnu
  • 4,377
  • 7
  • 26
  • 40
0
votes
1 answer

Adding information from one JsonBuilder object to another

As the title suggests, I'm trying to add information held in one JsonBuilder object to a second JsonBuilder object. Currently I have this: public String buildOneUser(DyveUserDTO user) { def userBuilder = new JsonBuilder() userBuilder…
0
votes
1 answer

Changing the labels jsonBuilder creates automatically in Groovy after converting Obj to JSON

I have a class called Case which is like: class Case { String caseId; Map > listOfCases = new HashMap>(); } I created several of these cases and add them to a list. Eventually I want to print…
AlexCon
  • 1,127
  • 1
  • 13
  • 31
0
votes
1 answer

Local variable used in jsonBuilder with Groovy

I would like to use a local variable previously defined in jsonBuilder. Here is my code: import groovy.json.JsonBuilder variable="""cols{id'Nom' label'LabelNom' pattern'' type'string'}{id'Test' label'Nom' pattern'' type'number'}""" def json = new…
0
votes
1 answer

Unable to reference local variable with JsonBuilder

I have the following code AddTicketCommand addTicketCommand = new AddTicketCommand(request.JSON) JsonBuilder jsonBuilder = new JsonBuilder() jsonBuilder { ticket { subject addTicketCommand.subject …
benstpierre
  • 32,833
  • 51
  • 177
  • 288
0
votes
1 answer

jsonbuilder: how to create map of objects

I've been trying to create a map of objects with jsonBuilder for a few hours already with no success. What I want to do is to create such json, so that I can adress my objects like this: someJsonObject.elements.2. Desired JSON looks like this (it's…
dulcyn
  • 65
  • 1
  • 3
  • 9