JOLT JSON字符串数组

时间:2017-07-19 19:55:19

标签: json jolt

我正在尝试将字符串数组转换为常规字符串。但是使用我的spec文件,它会以数组的形式返回

样本输入(来自ES)

{
    ...
    "hits": {
        "total": 1,
        "max_score": 1.4818809,
        "hits": [
            {
                "_index": "twitter",
                "_type": "tweet",
                "_id": "1",
                "_score": 1.4818809,
                "_source": {
                    "user": "test",
                    "message": "some message with the number 1",
                    "date": "2009-11-15T14:12:12",
                    "likes": 1
                },
                "highlight": {
                    "message": [
                        "some message with the <em>number</em> <em>1</em>"
                    ]
                }
            }
        ]
    }
}

规范文件

[
  {
    "operation": "shift",
    "spec": {
      "took": "took",
      "hits": {
        "total": "total_hits",
        "hits": {
          "*": {
            "_source": {
              "user": "Response[&2].firstName"
            },
            "highlight": {
              "message": ["Response[&2].h_message"]
            }
          }
        }
      }
    }
}
]

输出:

{
  "Response" : [ {
    "firstName" : "test",
    "h_message" : [ "some message with the <em>number</em> <em>1</em>" ]
  } ],
  "total_hits" : 1
}

正如您所看到的,“h_message”将作为一个数组出现。我想获得的是一个字符串/值

 "h_message" : [ "some message with the <em>number</em> <em>1</em>" ]

1 个答案:

答案 0 :(得分:0)

解决了它

[
  {
    "operation": "shift",
    "spec": {
      "took": "took",
      "hits": {
        "total": "total_hits",
        "hits": {
          "*": {
            "_source": {
              "user": "Response[&2].firstName"
            },
            "highlight": {
              "message": {
                "*": "Response[&0].h_message"
              }
            }
          }
        }
      }
    }
}
]