Skip to content

Add support for JSON configuration files#715

Closed
dancrumb wants to merge 6 commits intodocker:masterfrom
dancrumb:feature/support-json-config
Closed

Add support for JSON configuration files#715
dancrumb wants to merge 6 commits intodocker:masterfrom
dancrumb:feature/support-json-config

Conversation

@dancrumb
Copy link
Copy Markdown

@dancrumb dancrumb commented Dec 8, 2014

I switched over to crane because of a Fig issue and have invested heavily in JSON configuration files.

I'd like to start using Fig again, but switching from JSON to YAML will be a pain.

It seems pretty trivial for Fig to support JSON as well as YAML for input file format. Thence this Pull Request.

@dancrumb
Copy link
Copy Markdown
Author

dancrumb commented Dec 8, 2014

Not sure why it doesn't show the build status in this PR.

Anyway, here it is:

wercker status

Comment thread tests/integration/cli_test_json.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if these new integration tests really provide much extra coverage. Your change is appropriately isolated to just one module. A single integration test of that module (showing that a json file is read and returns the expect dict), should be sufficient.

The test suite is pretty slow as it is, we should avoid making it slower unless the tests actually add new coverage.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - this file will be removed

@dnephin
Copy link
Copy Markdown

dnephin commented Dec 16, 2014

I'm a big fan of YAML. Being able to add comments, and cleaner syntax is huge. I understand there are some gotchas, but it's so prevalent now, that you learn them pretty quick.

That said, I'm not against adding this support. I think it's a small enough change, and I understand everyone doesn't share my appreciation for YAML.

@dancrumb
Copy link
Copy Markdown
Author

I really miss the the ability to add comments :)

However, our environment is heavily biased towards Node and being able to operate on JSON files is much more convenient that YAML files.

I'm pretty confident that YAML/JSON won't result in a bifurcation of your code (which is the biggest risk from adding support for a secondary input format). I think this code converts to a Python structure early enough that your code will be safe.

@dancrumb
Copy link
Copy Markdown
Author

Updates made and build is passing

@aanand
Copy link
Copy Markdown

aanand commented Dec 17, 2014

Interesting. I can see an argument for supporting JSON in that it makes it easier to generate configuration files, but then I'm not sure if that's something we want to encourage. (What's your use case, and would it be equally well served by an import mechanism and/or parameterisation of configuration values?)

Thanks for the contribution - I need to think about it some more.

@thaJeztah
Copy link
Copy Markdown
Member

I'm +1 on having JSON as an alternative format. I fully understand the advantage of YAML (comments and cleaner, more human readable). JSON is natively supported by just about any language, so for automated generation and/or editing of a Fig-stack definition, I think this is a big win.

I'm not sure if that's something we want to encourage.

All examples in the documentation can keep using YAML, to emphasise it's the "standard" format. An extra section / note "alternative formats" can be added to show that JSON is also supported.

@jerem
Copy link
Copy Markdown

jerem commented Jan 5, 2015

JSON is a subset of YAML so this should already work out of the box with the current YAML parser.

@dancrumb
Copy link
Copy Markdown
Author

dancrumb commented Jan 5, 2015

Parsing the file is actually the smallest part of this change.
Also, since invalid JSON files can be valid YAML files and valid JSON files with duplicate IDs are not valid JSON files, I think using a YAML parser on JSON could cause confusion down the line with no added benefit.

@atrauzzi
Copy link
Copy Markdown

atrauzzi commented Feb 1, 2015

👍 for JSON configs for reasons like this:

Note: When mapping ports in the HOST:CONTAINER format, you may experience 
erroneous results when using a container port lower than 60, because YAML will 
parse numbers in the format xx:yy as sexagesimal (base 60). For this reason, we 
recommend always explicitly specifying your port mappings as strings.

@dnephin
Copy link
Copy Markdown

dnephin commented Aug 25, 2015

Since the Yaml parser supports JSON documents I'm reluctant to make any code changes here. It might be worth mentioning in the docs that you can use JSON, it's just "not considered a supported feature, even thought it should work in most cases".

@dnephin
Copy link
Copy Markdown

dnephin commented Oct 29, 2015

This will be documented in #2291

@dnephin dnephin closed this Oct 29, 2015
infraAnchor pushed a commit to infraAnchor/compose that referenced this pull request Mar 6, 2026
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

Successfully merging this pull request may close these issues.

6 participants