From the GraphAPI I receive the following (pre-filtered) response, however there are still values that I don't want. I want to keep it as simple as possible, but not sure which approach is the best here. One of the approaches I tried is posted down here.
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('[email protected]')/messages(sender,subject,body)",
"value": [
{
"@odata.etag": "W/\"6xAAAAAAKq\"",
"id": "6xAAAAAAVQAAA=",
"subject": "Can we speak tomorrow?",
"body": {
"contentType": "text",
"content": "Meeting at 10?"
},
"sender": {
"emailAddress": {
"name": "test-mail",
"address": "[email protected]"
}
}
},
{
"@odata.etag": "W/\"6xAAAAAAKq\"",
"id": "6xAAAAAAVQAAA=",
"subject": "Meet for lunch?",
"body": {
"contentType": "text",
"content": "The new cafeteria is open."
},
"sender": {
"emailAddress": {
"name": "test-mail",
"address": "[email protected]"
}
}
},
{
"@odata.etag": "W/\"6xAAAAAAKq\"",
"id": "6xAAAAAAVQAAA=",
"subject": "Nice city",
"body": {
"contentType": "text",
"content": "Want to join me on a business trip?"
},
"sender": {
"emailAddress": {
"name": "test-mail",
"address": "[email protected]"
}
}
}
]
}
The result should look like this:
{
"Messages": [
{
"id": "6xAAAAAAVQAAA=",
"sender": "[email protected]",
"subject": "Can we speak tomorrow?",
"content": "Meeting at 10?"
},
{
"id": "6xAAAAAAVQAAA=",
"sender": "[email protected]",
"subject": "Meet for lunch?",
"content": "The new cafeteria is open."
},
{
"id": "6xAAAAAAVQAAA=",
"sender": "[email protected]",
"subject": "Nice city",
"content": "Want to join me on a business trip?"
}
]
}
I have tried the following, but can't really get my head around it.
[
{
"operation": "shift",
"spec": {
"value": {
"*": {
"id": "value.[&1].id",
"sender": "value.[&1].sender.emailAddress.address",
"subject": "value.[&1].subject",
"body": "value.[&1].sender.emailAddress.address"
}
}
}
}
]
CodePudding user response:
It's a good idea to walk through the indices of the value list within a shift transformation spec. You can prefer addressing the attributes, which are not in the current object, by @(0,elm_at_surr_level.sub_elm_level1.sub_elm_level2)
reference as key such as
[
{
"operation": "shift",
"spec": {
"value": {
"*": {
"id": "Messages.[&1].&",
"@(0,sender.emailAddress.address)": "Messages.[&1].sender",
"subject": "Messages.[&1].&",
"@(0,body.content)": "Messages.[&1].content"
}
}
}
}
]
If sorting as displayed(in the order of id
->sender
->subject
->content
) needed, then that would be a bit tricky such as
[
{
"operation": "shift",
"spec": {
"value": {
"*": {
"id": "Messages.[&1].&",
"@(0,sender.emailAddress.address)": "Messages.[&1].sender",
"subject": "Messages.[&1].&",
"@(0,body.content)": "Messages.[&1].zontent"
}
}
}
},
{
"operation": "sort"
},
{
"operation": "shift",
"spec": {
"Messages": {
"*": {
"*": "&2.[&1].&",
"z*": "&2.[&1].c&(0,1)"
}
}
}
}
]