Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8087413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:46:05+00:00 2026-06-05T18:46:05+00:00

I am writing a Grails/Groovy app and I have a JSON object with a

  • 0

I am writing a Grails/Groovy app and I have a JSON object with a “string” name (grommet and widget) inside the params member that can change. That is, next time it might be acme and zoom. Here is the JSON:

def jx = """{ 
    "job": "42",
    "params": {
        "grommet": {"name": "x", "data": "y"},
        "widget": { "name": "a", "data": "b"}
    } 
}"""

I am trying to figure out how to get the string grommet . Code so far:

def dalist = new JsonSlurper().parseText(jx)
println dalist.job     // Gives: 42
println dalist.params  // Gives: [grommet:[name:x, data:y], widget:[name:a, data:b]]
println dalist.params[0]  // Gives: null

Any idea how to get the string grommet? Iama going to keep hitting my head against a wall.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:46:07+00:00Added an answer on June 5, 2026 at 6:46 pm

    The params key on the JSON object is associated with a JSON object, not an array, so you cannot access it by index. JsonSlurper maps JSON objects to Groovy Maps, so you can access params by its keys, which are strings, e.g. dalist.params.grommet, which will give you the map [name: 'x', data: 'y'].

    To access the keys on the params you can do dalist.params.keySet(), which will give you the list ['grommet', 'widget']. If you are interested in just knowing params keys, that should do the trick. If you need to get the 'grommet' string for some reason, you can do it by accessing the first element on that list, i.e. dalist.params.keySet()[0], but i don’t know why you would want to know that. And i’m not sure if it is guaranteed that the first key of that map will always be 'grommet', as JSON objects are unordered by the spec (from json.org: An object is an unordered set of name/value pairs), but, in turn, Groovy maps are ordered (the default implementation is LinkedHashMap)… so i would assume that the order is preserved when parsing JSON to the Groovy world, but i’d try not to rely on that particular behavior hehe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Grails app and I have a quick question about the
I'm writing an application in groovy with grails that needs to do some automated
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I'm writing a Grails app which I'd like 3rd parties to augment at runtime.
I'm half way through writing my first grails app. It's going really well so
I am writing a web app in Grails with the Acegi/Spring Security plug-in, and
I am working in Grails. I am writing a code that deletes the account
//Writing a letter #include <iostream> using namespace std; int main() { string first_name; //Name
I am writing a Grails app, and I want the controller to hit some
I'm using webflows in Grails and I'm currently writing tests for it. Now, inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.