json2yaml
3.0.1, released 4 years ago by dart-borg.dev
Converts JSON maps to YAML strings with beautification and pubspec conventions.
What it does
json2yaml turns a Dart Map into a YAML string. It handles nested structures, automatically beautifies the output, and supports pubspec.yaml and pubspec.lock formatting styles.
AI-written summary of version 3.0.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need to generate YAML from JSON data in a Dart project
- Creating or updating pubspec.yaml or pubspec.lock files programmatically
- Debugging or inspecting JSON structures in YAML format
Skip it when
- Performance critical code where string conversion overhead matters
- When advanced YAML features (anchors, tags, custom types) are required
Strengths
- Accurate handling of nested JSON structures
- Built‑in beautifier for readable output
- Dedicated pubspec.yaml and pubspec.lock formatting styles
- Simple API: single function call
Weaknesses
- No word wrapping for long strings
- Limited formatting options beyond the three styles
- Not a full YAML parser/serializer
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
const developerData = {
'name': "Martin D'vloper",
'job': 'Developer',
'skill': 'Elite',
'employed': true,
'foods': ['Apple', 'Orange', 'Strawberry', 'Mango'],
'languages': {
'perl': 'Elite',
'python': 'Elite',
'pascal': 'Lame',
},
'education': '4 GCSEs\n3 A-Levels\nBSc in the Internet of Things'
};
print(json2yaml(developerData));Alternatives
Packages that do the same job and could replace json2yaml.
- yaml
Provides full YAML parsing and serialization capabilities, suitable if you need more control over YAML output or need to read YAML back into Dart
92Compare - pubspec_parse
Can parse pubspec.yaml files but does not provide JSON to YAML conversion
93Compare
Works with
Packages commonly used together with json2yaml: ones it builds on, ones built on it, and its own family.