首页 > 解决方案 > 如何在yaml中的对象内嵌套数组?

问题描述

假设您Map<String, Object>在 YAML 中有一个名为“某物”

something:

对应的 JSON 应该是这样的: json

 "something": {
      "else": "then",
      "array": [
         "element in array"
       ]
    } 

所以对于这个 yaml 规范可能是:

something:
  else: then
  array: 
    - element in array

但既然something是地图,它不会让我做

array: 
  - element in array

或这个

array: ['element in array']

所以问题是 yaml 应该是什么来获得上述 JSON 考虑something是否有Map<String, Object>可能?

这是关于 ServiceCatalogDefinition 的定义,用于实现 OpenServiceBroker API。

使用 Yaml 的 OSB 目录

OSB 目录 json 看起来像这样

我正在尝试根据需要制作上述链接中架构中提到的“属性”。为此,我需要让它像这样返回 json:

"properties" : {
  "someProperty" : {
      "description": "description",
      "type": "string"
   },
  "required": [
    "someProperty"
   ]    
}

yaml 在我的 application.yml 中进行验证,抛出评论中提到的错误

标签: jsonyaml

解决方案


使用站点json2yaml,您将获得 YAML :

---
something:
  else: then
  array:
  - element in array

来自 json :

{  
  "something": {
      "else": "then",
      "array": [
         "element in array"
       ]
    } 
}

与您相比,我认为您的“-”必须与“array”处于同一级别。


推荐阅读