Ability to dump configuration to JSON
boosh opened this issue · comments
Hi,
It'd be really useful to be able to access the expanded YAML with all inheritance expanded, etc. so the configuration can be converted/processed with other tools as normal YAML. I'm trying to use configure to make it easy to generate JSON, but json.dumps() won't work :-(
Really useful module, thanks!
configure uses YAML tags to specify configuration actions — it would be difficult to do that for JSON. Could you explain why you want use JSON or what is your use case?
—
Andrey Popp
On Wed, May 1, 2013 at 7:38 PM, 0d51e69a notifications@github.com wrote:
Hi,
It'd be really useful to be able to dump the parsed configuration to different output formats, especially JSON.Really useful module, thanks!
Reply to this email directly or view it on GitHub:
#3
I'd like to use configure to help me generate Amazon CloudFormation templates. For example I might represent a template with the following YAML:
AWSTemplateFormatVersion: 2010-09-09
Description: Sets up an RP tier, web tier and a master. No pre-existing EIPs are required.
Parameters:
InstanceType: &InstanceType
Description: Default EC2 instance type
Type: String
Default: t1.micro
NoEcho: "False" # Booleans must be quoted
AllowedValues:
- t1.micro
- m1.small
- m1.medium
ConstraintDescription: Must be a valid EC2 instance type.
MasterInstanceType:
<<: *InstanceType
Description: Master EC2 instance type
Mappings:
AWSInstanceType2Arch:
t1.micro:
- Arch: "64" # numbers must be quoted
m1.small:
- Arch: "64"
m1.medium:
- Arch: "64"
AWSRegionArch2AMI:
eu-west-1:
- 32: ami-018bb975
- 64: ami-f2191786
...
I'd then like to be able to load this using configure (so I can use composition, inheritance between files, etc) and output JSON.
Also, I only want a "one-way" translation from YAML to JSON of the final compiled data structure since the JSON will be used as an input into the Amazon API - I won't ever want to translate it back to YAML.
I've implemented something that works with PyYAML (https://bitbucket.org/boosh/jayc/src - in fact because this is simpler it can convert both ways). But since configure adds additional useful features, it'd be awesome if it was possible to dump the internal data structure to JSON. I tried to get it working with configure but the json dumper kept giving me errors that I couldn't resolve.
Thanks
@boosh right, this is because json
doesn't know how to handle configure.Configuration
. I suggest you to use jsonpublish library to deal with such use cases — there's an example https://gist.github.com/andreypopp/7104f64dc583de94835c
I think we can close this issue.
That's great, thanks.