Create json in Groovy
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Create json in Groovy
Need to create Json like this
"data":
{
"data1":"data1",
"data2":"data2"
}
}
I'm able to create the below one but not the above one. I'm using def json = new JsonOutput().toJson(obj) for the below
{
"data1":"data1",
"data2":"data2"
}
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
@henil_shah, have you managed to accomplish the task?
If you haven't, could you please provide the information that @nmrao requested?
Thanks in advance.
Olga Terentieva
SmartBear Assistant Community Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Input data will be in Groovy script with random data provided to a test case. I'm able to create simple Json but not this kind of Json
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Would you please check this script
You may test it online in the above link.
import static groovy.json.JsonOutput.toJson import static groovy.json.JsonOutput.prettyPrint def data = [data1: "data1", data2: "data2"] def jsonString = prettyPrint(toJson(data: data).toString()) log.info jsonString
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, @nmrao .
@henil_shah , does the above suggestion help?
Olga Terentieva
SmartBear Assistant Community Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Olga_T,
Some time members float the thread with messages. And do not reply once the solution is posted. There could be multiple reasons for being delayed in reply. But, it would be encouraging if reply is prompt on the solutions or providing with feedback.
This message is not just specific to this case, it is the case in general. I do notice that it happens even the members are online, no reply after the solution recieved.
Thank you for taking a look.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@nmrao , I agree. I would be happy if this helps find a solution faster.
Some users looking for information in the existing topics prefer going through only those topics that are marked as solved. So, this can increase the chances for them to find useful information.
I hope to see this topic solved soon
Regards,
Olga Terentieva
SmartBear Assistant Community Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess we could mark Rao's reply as a solution for now.
@henil_shah feel free to post any updates here if you would like to find alternative ways to solve this.
Best regards,
Olga Terentieva
SmartBear Assistant Community Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
