json2yaml 1.0.0+1 copy "json2yaml: ^1.0.0+1" to clipboard
json2yaml: ^1.0.0+1 copied to clipboard

outdated

Dart package to render JSON data to YAML

json2yaml Build Status codecov pubspec_lock version #

Dart package to render JSON data to YAML

json2yaml() #

json2yaml is function called to format Json as 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));

This function is implemented in a very basic and maybe a naive way, please let me know if it does not work for you.

Usage #

To use json2yaml, add the following dependency to pubspec.yaml:

dependencies:
  json2yaml: ^1.0.0

Advanced usage: Yaml formatting styles #

json2yaml supports an optional argument to customize Yaml formatting for different use cases. At the moment, it supports three styles:

  • YamlStyle.generic (default) -- generic Yaml rendering
  • YamlStyle.pubspecYaml -- Yaml formatting style mimicking pubspec.yaml files
  • YamlStyle.pubspecLock -- Yaml formatting style mimicking pubspec.lock files generated by Dart pub

Yaml style is supplied as an optional argument of 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,
});
12
likes
0
pub points
90%
popularity

Publisher

unverified uploader

Dart package to render JSON data to YAML

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on json2yaml