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

Q: Simple JSON nested object to HCL #192

Closed
mgutz opened this issue Mar 30, 2017 · 4 comments
Closed

Q: Simple JSON nested object to HCL #192

mgutz opened this issue Mar 30, 2017 · 4 comments

Comments

@mgutz
Copy link

mgutz commented Mar 30, 2017

What is the HCL equivalent of this JSON?

{
    "hcl": { "key": 1 }
}

I try this

hcl = {
   key = 1
}

And get

{
  "hcl": [{"key": 1}]
}
@sethvargo
Copy link
Contributor

Hi @mgutz

Thank you for opening an issue. HCL parses this way because it's possible to have multiple objects like this:

hcl {
  key = 1
}

hcl {
  key = 2
}

In this case, which hcl block would win? There is no HCL equivalent JSON in your case. You can either flatten the HCL into a single object at parsing, or alter your program to handle an array of objects instead of a single object.

Hope this helps!

@mgutz
Copy link
Author

mgutz commented Mar 30, 2017

The README says "fully compatible" with JSON. Maybe that should be changed.

I was aware of the block case. I thought explicitly using assignment = might do what I want as opposed to treating it as a repeatable block.

@sethvargo
Copy link
Contributor

Hi @mgutz

It is fully-compatible. That HCL maps directly to JSON.

@rwiggins
Copy link

rwiggins commented May 9, 2018

If you're here because of Consul's HCL config, which at the time of writing is not really documented, it looks like Consul has some code to manually patch up the above behavior, see here.

That ends up translating

performance {
    raft_multiplier = 1
}

which normally in HCL corresponds to

{
    "performance": [{
        "raft_multiplier": 1
    }]
}

into (for Consul specifically)

{
    "performance": {
        "raft_multiplier": 1
    }
}

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

3 participants