搜尋套件、儲存庫與 APP 分類

套件詳情v3.0.1

json2yaml

Dart 套件,用於將 JSON 數據轉換為 YAML,內建自動美化功能,並支援 Dart pubspec.yaml 和 pubspec.lock 慣例

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
9.9萬
喜歡數
12
Pub 分數
160

安裝套件

flutter pub add json2yaml

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Dart 套件,可將 JSON 數據轉換為 YAML 格式並自動格式化。它支援 Dart 的 pubspec.yaml 和 pubspec.lock 檔案中使用的慣例,非常適合用於設定和相依性管理任務。此套件可確保輸出乾淨、易讀,並能順暢整合至跨多個平台的 Flutter 和 Dart 專案中。

適用情境

  • 將 JSON 配置轉換為 YAML
  • 生成 pubspec.yaml 檔案
  • 解析和渲染依賴項清單
  • 自動化設定檔產生
  • 在 JSON 和 YAML 格式之間同步資料

主要特色

  • YAML 輸出的自動美化
  • 對 pubspec.yaml 和 pubspec.lock 約定的支援
  • 透過 flutter pub add 簡單整合
  • 跨平台相容性
  • 輕量且高效的解析
  • 維持資料結構完整性

適合對象

  • Dart 與 Flutter 開發人員
  • CI/CD 流水線自動化
  • 設定管理
  • 工具與程式碼產生腳本
  • 需要 JSON 到 YAML 轉換的專案

使用建議

  • 僅限基本 YAML 格式
  • 無模式驗證
  • 不支援複雜的 YAML 功能,例如錨點或別名
  • 取決於輸入JSON的有效性
  • 可能不支援嵌套結構中的所有邊緣情況

原始 README

以下為關聯原始碼儲存庫的 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,
});

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案