I am trying to extract certain fields from the following JSON object using a liquid template in a SharePoint site, but I am not getting the desired output.
Here is the JSON object:
{
"value": [
{
"searchTerms": [],
"hitsContainers": [
{
"hits": [
{
"hitId": "00000000-0000-0000-0000-000000000000",
"rank": 11000000,
"summary": " Desc: aaa<ddd/>",
"resource": {
"@odata.type": "#microsoft.graph.listItem",
"fields": {
"linkFilename": "TEST-DOC5.pdf",
"documenttype": "schema",
"description": "Schema1 of Object1"
},
"webUrl": "https://1234.sharepoint.com/sites/site1/XX/TEST-DOC5.pdf"
}
},
{
"hitId": "11111111-1111-1111-1111-111111111111",
"rank": 12000000,
"summary": " Desc: bbb<ddd/>",
"resource": {
"@odata.type": "#microsoft.graph.listItem",
"fields": {
"linkFilename": "Document.pdf",
"documenttype": "drawing",
"description": "A test PDF"
},
"webUrl": "https://1234.sharepoint.com/sites/site2/YY/Document.pdf"
}
}
],
"total": 2,
"moreResultsAvailable": false
}
]
}
],
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}
And here is the liquid template that I am using:
{% assign data = value[0].hitsContainers[0].hits[0] %}
{% for field in data.resource.fields %}
"{{ field[0] }}": "{{ field[1] }}"
{% endfor %}
The expected output is:
"linkFilename": "TEST-DOC5.pdf"
"documenttype": "schema"
"description": "Schema1 of Object1"
But the actual output is:
"": ""
"": ""
"": ""
I am not sure why I am not getting the desired output. Can anyone help me in this?