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

Array at root? #90

Open
tamboril opened this issue Dec 20, 2016 · 4 comments
Open

Array at root? #90

tamboril opened this issue Dec 20, 2016 · 4 comments

Comments

@tamboril
Copy link

If the JSON I want is an array at the top level, how do I parse that from a HOCON string?

I get an exception when parsing "[ { op: replace } ]"
string: has type list rather than object at file root

@Magisus
Copy link
Contributor

Magisus commented Dec 20, 2016

JSON specifically does not allow you to parse something that does not have curly braces at root. Reading through the docs, it looks like HOCON allows you to omit the curly braces, but it still assumes that the thing at root can be converted to an object, which a list cannot. You could try adding curly braces around it (not sure if that's an option). I'd need to investigate more to come up with other solutions, but the code that is erroring is here: https://github.com/puppetlabs/cpp-hocon/blob/master/lib/src/parseable.cc#L124. That function is the last thing called before the config object gets returned, so it attempts to coerce everything to an object at the top level.

@tamboril
Copy link
Author

tamboril commented Dec 20, 2016

After double-checking RFC 4627, I'm pretty sure an array at the top is allowed. It can be either an object or an array.

Works with nlohmann's library and on jsonlint.com: [ {"a": 1} ]

@Magisus
Copy link
Contributor

Magisus commented Dec 20, 2016

Yeah you're right, I found the place that specifies that now... I'll have to play around with it more to see if we ever tested that functionality, and if not, where our code differs from the code that supports that.

@MikaelSmith
Copy link
Contributor

https://github.com/lightbend/config/blob/master/HOCON.md#include-semantics-merging specifically talks about this behavior of both HOCON and JSON, and how included files differ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants