Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

How to join two json objects into key value pairs using JMESPATH

The below JSON has had me stumped for hours.

The DataSource.Headers contains the headers for all over the values contained in the DataSource.Rows.

I'm trying to get the Header in position [0] to correspond with the value [0] in each DataSource.Rows object into a Key:Value pair response. Is this possible?

I've been tinkering with the merge and join functions, but can't seem to get them to work.

Here is the input JSON:

{
  "DataSource": {
    "Name": "Test Data",
    "Headers": [
      {
        "Name": "ID",
        "DisplayAt": "None"
      },
      {
        "Name": "UserID",
        "DisplayAt": "Title"
      },
      {
        "Name": "Date",
        "DisplayAt": "None"
      },
      {
        "Name": "Number",
        "DisplayAt": "None"
      },
      {
        "Name": "Documentation",
        "DisplayAt": "None"
      },
      {
        "Name": "Documentation Type",
        "DisplayAt": "None"
      },
      {
        "Name": "VID",
        "DisplayAt": "None"
      }
    ],
    "Rows": [
      [
        "bcf002c4-0466-4bdc-bef2-aca10144571c",
        "e6363955-5701-415d-b18c-aca1014457b4",
        "2020-01-01",
        "12345",
        "Test Data",
        "Document",
        "54321"
      ],
      [
        "633c184a-1594-4144-a1fb-aca800f81bb5",
        "ebe3df2a-dfe5-4a7c-b388-aca800f81c4d",
        "2021-01-01",
        "99999",
        "Test Data 2",
        "Document 2",
        "99999"
      ]
    ],
    "TotalRows": 2,
    "LastUpdated": "2021-01-08T03:04:02.3500000Z",
  }
}

Here is the result I'm trying to get.

[
  {
   "ID": "bcf002c4-0466-4bdc-bef2-aca10144571c",
   "UserID": "e6363955-5701-415d-b18c-aca1014457b4",
   "Date": "2020-01-01",
   "Number": "12345",
   "Documentation": "Test Data", 
   "Documentation Type": "Document",
   "VID": "54321",
},
{
   "ID": "633c184a-1594-4144-a1fb-aca800f81bb5",
   "UserID": "ebe3df2a-dfe5-4a7c-b388-aca800f81c4d",
   "Date": "2021-01-01",
   "Number": "99999",
   "Documentation": "Test Data 2", 
   "Documentation Type": "Document 2",
   "VID": "99999",
  }
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...