【问题标题】:Parse JSON document based on predefined JSON mapping document in Java基于 Java 中预定义的 JSON 映射文档解析 JSON 文档
【发布时间】:2022-01-06 02:09:17
【问题描述】:

我想知道是否有任何 Java 中的库 可用于过滤基于预定义 JSON 映射文档的 JSON 文档,或者实现这一点的唯一方法是编写自定义 java 代码。

如果需要编写 Java 自定义代码,我应该遵循哪种类型的设计模式或数据结构。任何建议将不胜感激。

例子-

输入 JSON 文档 -

{
  "basicInfo": {
    "name": "name",
    "age": "25",
    "address": "address"
  },
  "education": [
    {
      "ug": {
        "unversity": "university",
        "major": [
          "cs",
          "ds"
        ],
        "year": "2012"
      },
      "pg": {
        "unversity": "university",
        "major": [
          "cs",
          "ds"
        ],
        "year": "2015"
      }
    }
  ]
}

预定义的 JSON 映射文档(可以定义为任何 JSON 格式,下面是我创建的一个这样的示例)-

{
    "definitions": {
      "basicInfo": {
        "maxOccurance": "1",
        "fields": [
          {
            "key": "name",
            "type": "S",
            "lenght": "50",
            "usage": "M",
            "maxOccurrance": "1"
          },
          {
            "key": "age",
            "type": "S",
            "lenght": "3",
            "usage": "O",
            "maxOccurrance": "1"
          }
        ]
      },
      "education": {
        "maxOccurance": "10",
        "fields": [
          {
            "pg": {
              "maxOccurance": "1",
              "fields": [
                {
                  "key": "university",
                  "type": "S",
                  "lenght": "50",
                  "usage": "M",
                  "maxOccurrance": "1"
                },
                {
                  "key": "major",
                  "type": "S",
                  "lenght": "3",
                  "usage": "O",
                  "maxOccurrance": "1"
                }
              ]
            }
          }
        ]
      }
    }
  }

预期的输出 JSON 文档

{
    "basicInfo": {
      "name": "name",
      "age": "25"
    },
    "education": [
      {
        "pg": {
          "unversity": "university",
          "major": "cs"
        }
      }
    ]
  }

【问题讨论】:

  • 我们paste JSON stringpaste JSON string时,像Visual Studio这样的IDE支持生成类,让这种工作更容易。检查是否有任何 Java IDE 也支持。
  • @AnandSowmithiran 感谢您提供的信息,我正在寻找一种基于预定义 JSON 规格表/JSON 映射文档过滤 JSON 文档的方法。那么是否有一个现成的实用程序可以读取 JSON 规范文档并过滤输入 JSON 文档并生成示例中提到的输出 JSON 文档。
  • 好的,明白了。检查这个名为 jolt 的库是否满足您的要求。
  • 是的,浏览文档,看起来它对需求很有用。谢谢。

标签: java json algorithm design-patterns jsonparser


【解决方案1】:

请求是基于预定义的 JSON 规格表/JSON 映射文档过滤 JSON 文档的方法。 jolt 库可能能够满足此要求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多