Search packages, repositories and app categories

Package detailsv3.0.1

json2yaml

Dart package to render JSON data to YAML with built-in automatic beautifier and support for Dart pubspec.yaml and pubspec.lock conventions

AndroidiOSWebmacOSWindowsLinux
30-day downloads
98.7K
Likes
12
Pub points
160

Install package

flutter pub add json2yaml

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Dart package that converts JSON data into YAML format with automatic formatting. It supports conventions used in Dart's pubspec.yaml and pubspec.lock files, making it ideal for configuration and dependency management tasks. The package ensures clean, readable output and integrates seamlessly into Flutter and Dart projects across multiple platforms.

Use cases

  • Converting JSON configurations to YAML
  • Generating pubspec.yaml files
  • Parsing and rendering dependency manifests
  • Automating configuration file generation
  • Synchronizing data between JSON and YAML formats

Key features

  • Automatic beautification of YAML output
  • Support for pubspec.yaml and pubspec.lock conventions
  • Simple integration via flutter pub add
  • Cross-platform compatibility
  • Lightweight and efficient parsing
  • Preserves data structure integrity

Suitable for

  • Dart and Flutter developers
  • CI/CD pipeline automation
  • Configuration management
  • Tooling and code generation scripts
  • Projects requiring JSON-to-YAML conversion

Considerations

  • Limited to basic YAML formatting
  • No schema validation
  • Not designed for complex YAML features like anchors or aliases
  • Dependent on input JSON validity
  • May not support all edge cases in nested structures

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

json2yaml Build Status pubspec_lock version

Dart package to render JSON data to YAML:

  • Correct handling of nested structures
  • Built-in automatic beautifer
  • Supports Dart pubspec.yaml conventions
  • Compatible with conventions imposed by Dart pubspec.lock generator

Known limitations

  • Strings (single line and multiline) are always formatted as they are, without word wrapping for better human readability

json2yaml()

json2yaml is the function to format JSON data to YAML.

  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));

Advanced usage: YAML formatting styles

json2yaml supports the optional argument to customize YAML formatting for various use cases. At the moment, it supports the three following formatting styles:

  • YamlStyle.generic (default) -- Default formatting style applicable in most cases
  • YamlStyle.pubspecYaml -- YAML formatting style following pubspec.yaml formatting conventions
  • YamlStyle.pubspecLock -- YAML formatting style following pubspec.lock formatting conventions

YAML style is supplied as an optional argument to json2yaml():

/// Yaml formatting control options
enum YamlStyle {
  generic,
  pubspecYaml,
  pubspecLock,
}

/// Converts JSON to YAML representation
String json2yaml(
  Map<String, dynamic> json, {
  YamlStyle yamlStyle = YamlStyle.generic,
});

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package