FLUTTER ECOSYSTEM

alexei-sintotski/json2yaml

JSON 데이터를 YAML로 렌더링하는 Dart 패키지

json2yaml 프로젝트 이미지
Stars
16
Forks
11
최근 푸시(UTC)
2023. 7. 23.
프로젝트 상태
활성
Alexei Sintotski GitHub avatar
GITHUB User

Alexei Sintotski ↗

언어DartShell

기술 주제

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 5 개

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

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