Universal configuration file format converter for JSON, YAML, and TOML.
package.json to pyproject.toml or vice versa.yaml ↔ .json)FormatExtensionsUse CasesJSON.jsonnpm, Node.js, VS Code settingsYAML.yaml, .ymlDocker Compose, GitHub Actions, KubernetesTOML.tomlPython Poetry, Rust Cargo, Go modules
python
import json
import yaml
import toml
# JSON to YAML
with open('package.json') as f:
data = json.load(f)
with open('package.yaml', 'w') as f:
yaml.dump(data, f, default_flow_style=False, sort_keys=False)
# YAML to JSON
with open('docker-compose.yaml') as f:
data = yaml.safe_load(f)
with open('docker-compose.json', 'w') as f:
json.dump(data, f, indent=2)
# TOML to JSON
with open('pyproject.toml') as f:
data = toml.load(f)
with open('pyproject.json', 'w') as f:
json.dump(data, f, indent=2)
python
import json
import yaml
def validate_json(filepath):
try:
with open(filepath) as f:
json.load(f)
return True, "Valid JSON"
except json.JSONDecodeError as e:
return False, str(e)
def validate_yaml(filepath):
try:
with open(filepath) as f:
yaml.safe_load(f)
return True, "Valid YAML"
except yaml.YAMLError as e:
return False, str(e)
python
import json
# Compact to pretty JSON
with open('config.min.json') as f:
data = json.load(f)
with open('config.json', 'w') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
python
import json
import toml
# Read package.json
with open('package.json') as f:
pkg = json.load(f)
# Create pyproject.toml structure
pyproject = {
'tool': {
'poetry': {
'name': pkg.get('name', ''),
'version': pkg.get('version', '0.1.0'),
'description': pkg.get('description', ''),
'authors': [],
'dependencies': {}
}
}
}
# Write TOML
with open('pyproject.toml', 'w') as f:
toml.dump(pyproject, f)
python
import yaml
import json
with open('docker-compose.yaml') as f:
compose = yaml.safe_load(f)
with open('docker-compose.json', 'w') as f:
json.dump(compose, f, indent=2)
sort_keys=False to preserve original key orderensure_ascii=False for international configsCommon issues and solutions:
IssueCauseFixScannerErrorInvalid YAML syntaxCheck indentation (spaces, not tabs)TomlDecodeErrorInvalid TOML syntaxVerify section headers [section]``JSONDecodeErrorTrailing commas in JSONRemove commas before } or ]Unicode errorsEncoding mismatchOpen files with encoding='utf-8'
bash
pip install pyyaml toml