Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Accessing array elements in a configuration #194

Closed
maasg opened this issue Sep 30, 2014 · 3 comments
Closed

[Question] Accessing array elements in a configuration #194

maasg opened this issue Sep 30, 2014 · 3 comments

Comments

@maasg
Copy link

maasg commented Sep 30, 2014

Given a nested JSON as configuration, like:

{
    app: {
        id: "app1"
        instances: 2,
        servers: [
            { host: "farm1.myco.com", port: 9876 }
            { host: "farm2.myco.com", port: 9876 }
        ]
    }
}

is it possible to address elements of an array directly in a path?

At the moment we need to do something like the following, which is kind of verbose:

val servers = config.getObjectList("app.id")
val server = servers.get(0).toConfig
val host = server.getString("host")
val port = server.getInt("port")

Something like this would be ideal:

val host = config.getString("app.id.servers.0.host") ?

Does the TypeSafe API supports something like this?

@havocp
Copy link
Collaborator

havocp commented Sep 30, 2014

There isn't a way now; I think #30 is the same request and has some (not very enlightening) discussion.

@maasg
Copy link
Author

maasg commented Oct 1, 2014

I see. Thanks.

For the record, my usecase is accessing some config in json format in which a list of servers is written by the config system (e.g Chef in our case) but where I only need the first element ("seed node"). It should be a valid usecase for a configuration and having to drop down to an array and go back to a config object seems to be like a broken path to me.

@havocp
Copy link
Collaborator

havocp commented Dec 27, 2014

Let's call this a duplidate of #30, so I'll close this copy.

@havocp havocp closed this as completed Dec 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants