简体   繁体   English

是否有在线工具可以为复杂的 JSON 有效负载生成 JSON 规范?

[英]Is there an online tool to generate the JSON Spec for a complex JSON payload?

I have a complex JSON payload with nested arrays.我有一个复杂的 JSON 有效载荷和嵌套的 arrays。 I need to create a JSON spec to output the same payload as I have today so that if the sending system added any new fields, I want them to be dropped.我需要为 output 创建一个 JSON 规范,与我今天的有效负载相同,这样如果发送系统添加了任何新字段,我希望它们被删除。 I need this capability because in TIBCO's Business Works, I need this output to be parsed against an XSD that I have generated for this JSON payload.我需要此功能,因为在 TIBCO 的 Business Works 中,我需要根据我为此 JSON 有效负载生成的 XSD 解析此 output。 Unfortunately, if new fields arrive in the JSON payload, the transform to XML using the XSD fails as it does a strict compare and there is currently no option to get around it in Business Works.不幸的是,如果新字段到达 JSON 有效负载中,则使用 XSD 转换为 XML 失败,因为它进行了严格的比较,目前在商业中没有解决它的选项。

My example of JSON is我的 JSON 示例是

{
  "items": [
    {
      "id": "000fd75c2b2fd30cadaae94c532d82f2408d95454996941002d8c8088157d03b",
      "sourceIdentifier": {
        "dataPartitionId": "877307a0-b5f5-4a01-9d4b-9fead6bcf788",
        "id": "103357"
      },
      "birthDate": "YYYY-MM-DD",
      "gender": {
        "codings": [
          {
            "code": "248153007",
            "display": "Male",
            "system": "2.16.840.1.113883.6.96"
          }
        ],
        "sourceCodings": [
          {
            "code": "248153007",
            "display": "Male",
            "system": "2.16.840.1.113883.6.96"
          }
        ],
        "text": "Male"
      }
    }
  ],
  "totalResults": 1,
  "firstLink": "xyz",
  "lastLink": "abc"
}

I want a JOLT spec that goes down and specifies each of the child elements of the above payload.我想要一个 JOLT 规范,它会下降并指定上述有效负载的每个子元素。 I have this simple spec below, but if the sending app added a new field it appears in the output as well and that is a problem for me.我在下面有这个简单的规范,但是如果发送应用程序添加了一个新字段,它也会出现在 output 中,这对我来说是个问题。

[
  {
    "operation": "shift",
    "spec": {
      "items": "items"
    }
  }
]

Any help is appreciated.任何帮助表示赞赏。 Thanks.谢谢。

To silently filter fields from the JSON string that are unknown to BusinessWorks (which means they are not defined in the XSD used by BusinessWorks) you can use the 'ignore additional JSON fields' option introduced in BW 6.6.1.要从 JSON 字符串中静默过滤 BusinessWorks 未知的字段(这意味着它们未在 BusinessWorks 使用的 XSD 中定义),您可以使用“忽略额外的 Z0ECD11C1D7A287401D148A23BBD76 字段中引入的选项。”。

See below extract from the release notes:请参阅以下发行说明的摘录:

Support is added to ignore additional JSON fields when processing a schema添加了支持以在处理模式时忽略其他 JSON 字段

For the other part of your question you can use the following Studio feature: .对于您问题的另一部分,您可以使用以下 Studio 功能:. Right click on the 'Schema' folder.右键单击“架构”文件夹。 Select 'News -> XML Schema File from JSON Payload' Select '新闻 -> XML 架构文件来自 JSON 有效负载'

But this approach has some limitations and I don't think it would manage arrays.但是这种方法有一些局限性,我认为它不能管理 arrays。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM