Logic apps convert a particular key from JSON object array to delimited string - azure-logic-apps

Here is my JSON object array:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects",
"value": [
{
"#odata.type": "#microsoft.graph.user",
"id": "b3cbd395-dfba-4d36-b6e5-161bf00c26a1",
"businessPhones": [],
"displayName": "Joe Bloggs",
"givenName": null,
"jobTitle": null,
"mail": "joebloggs#domain.com",
"mobilePhone": null,
"officeLocation": null,
"preferredLanguage": null,
"surname": null,
"userPrincipalName": "joebloggs_domain.com#EXT##domain2.onmicrosoft.com"
},
{
"#odata.type": "#microsoft.graph.user",
"id": "b0b80e63-5be2-44c9-87b7-e6ec52432796",
"businessPhones": [],
"displayName": "John Doe",
"givenName": "John",
"jobTitle": null,
"mail": "johndoe#domain.com",
"mobilePhone": null,
"officeLocation": null,
"preferredLanguage": null,
"surname": "Doe",
"userPrincipalName": "johndoe_domain.com#EXT##domain2.onmicrosoft.com"
}
]
}
I want to extract the mail key of each array object into a string like below so that I can then send an email to them later.
joebloggs#domain.com;johndoe#domain.com
I tried join(body('Parse_JSON_owners')?['value']?['mail'], ';') but that gives error:
The template language expression 'join(body('Parse_JSON_owners')?['value']?['mail'], ';')' cannot be evaluated because property 'mail' cannot be selected. Array elements can only be selected using an integer index.

You can initialise a string variable and use Append to string variable inside a For-each loop.
RESULT:

You could use the Select Data operation
With this Action you can map your objects to a new array of objects.
Select your source object, in your case that would be body('Parse_JSON_owners')
In order to only get an array with value types, you can first click on the switch button at the right side of the action.
Add your property, in your case that would be item()?['value']?['mail'].
Result output
In a run this would result in an array with plain string values.
After this, you can join the array the way you already had in mind, with the join function. This would look something like this: join(body('Select'), ';')

Related

How can I insert contract with ShippingAddress?

I want to register a new Contract Object.
However, when I try to register it together with ShippingAddress, I get an error.
How do I add a ShippingAddress with a Contract Object?
■ Field is not writeable: Contract.ShippingAddres
Contract cont = (Contract) parser.readValueAsStrict(Contract.class);
Address a = new Address();
a.country = 'Japan';
a.city = 'Tokyo';
cont.ShippingAddress = a;
insert cont;
I ran New Contract in the GUI, and the second of the arrays has ShippingAddress registered.
I would like to do this with the Apex API as well.
■ The ShippingAddress of the second record is registered.
[
{
"attributes": {
"type": "Contract",
"url": "/services/data/v56.0/sobjects/Contract/8000T000000223IQAQ"
},
"Id": "8000T000000223IQAQ",
"AccountId": "0010T00000Ox7sSQAR",
"BillingAddress": null,
"ShippingAddress": null,
"OwnerId": "0055g00000GRB5vAAH",
"Status": "Draft",
"StatusCode": "Draft",
"IsDeleted": false,
"ContractNumber": "00000114",
"CreatedDate": "2022-11-15T10:03:42.000+0000",
"CreatedById": "0055g00000GRB5vAAH",
"LastModifiedDate": "2022-11-15T10:03:42.000+0000",
"LastModifiedById": "0055g00000GRB5vAAH",
"SystemModstamp": "2022-11-15T10:03:42.000+0000",
"LastViewedDate": "2022-11-15T10:03:42.000+0000",
"LastReferencedDate": "2022-11-15T10:03:42.000+0000"
},
{
"BillingStreet": "西新宿1丁目",
"BillingCity": "新宿区",
"BillingState": "東京都",
"BillingPostalCode": "163-0590",
"BillingCountry": "日本",
"BillingAddress": {
"city": "新宿区",
"country": "日本",
"geocodeAccuracy": null,
"latitude": null,
"longitude": null,
"postalCode": "163-0590",
"state": "東京都",
"street": "西新宿1丁目"
},
"ShippingStreet": "西新宿1丁目",
"ShippingCity": "新宿区",
"ShippingState": "東京都",
"ShippingPostalCode": "163-0590",
"ShippingCountry": "日本",
"ShippingAddress": {
"city": "新宿区",
"country": "日本",
"geocodeAccuracy": null,
"latitude": null,
"longitude": null,
"postalCode": "163-0590",
"state": "東京都",
"street": "西新宿1丁目"
},
.....
}
]
https://developer.salesforce.com/docs/atlas.en-us.238.0.object_reference.meta/object_reference/compound_fields_address.htm
Standard address compound fields are read-only, and are only
accessible using the SOAP and REST APIs. See Compound Field
Considerations and Limitations for additional details of the
restrictions this imposes.
Instead set single fields inside the address.
cont.ShippingCountry = 'Japan';
cont.ShippingCity = 'Tokyo';
insert cont;

Deutschebahn API for departureboard not showing destination station

From this link:
https://developer.deutschebahn.com/store/apis/info?name=Fahrplan-Free&version=v1&provider=DBOpenData#!/default/get_departureBoard_id
I can successfully call the ARRIVALboard information:
[
{
"name": "ICE 1689",
"type": "ICE",
"boardId": null,
"stopId": 8000152,
"stopName": "Hannover Hbf",
"dateTime": "2021-01-19T00:00",
"origin": "Hamburg-Altona",
"track": "8",
"detailsId": "78642%2F27599%2F82706%2F15139%2F80%3fstation_evaId%3D8000152"
}
, which is complete.
However, when I call the DEPARTUREboard information I get everything apart from the 'destination' JSON field.
{
"name": "ICE 272",
"type": "ICE",
"boardId": null,
"stopId": 8000152,
"stopName": "Hannover Hbf",
"dateTime": "2021-01-19T00:05",
"track": "7",
"detailsId": "972312%2F330581%2F159824%2F244192%2F80%3fstation_evaId%3D8000152"
}
, i.e., the 'destination' field is missing according to the Model schema
I guess this is a user error but I can't work out how to fix this!

Ruby Map Complex Nested JSON to my own Ruby Class?

I need to be able to map a complex nested json from API result to my own custom class representation. Also need to be able to edit the data and send it back to API as json.
Tried searching on this previously. Could only find how to map to OpenStruct.
In other languages like C# I can do something like this:
public class SomeViewModel
{
public SomeViewModel(){
A = new AViewModel();
B = new BViewModel();
Cs = new List<C>();
}
public string D {get; set;}
}
Where A, B, and C are complex types (can contain other properties of other class types, arrays of class types, etc). I could then use a few libraries to map a JSON request to SomeViewModel and be able to access all properties and methods. Looking to do the same in Ruby.
My JSON contains many objects and array of objects. Some of the situations are an object with arrays of objects (arrays of objects can also contain arrays of objects) and nested arrays (which can also contain objects and arrays of objects). Now I'm aware that I could use the hash syntax notation but then I'd have to map each k-v pair individually. I'm sure there is a more DRY-er way in Ruby?
Let's say here is a JSON snippet (greatly reduced as the actual JSON is WAY too large and can't use real data anyway):
"SomeViewModel": {
"Bank": {
"ID": 585263,
"BankName": "First Bank of CA",
"Drawer": null,
"LockDate": "2020-02-24T08:45:13.507",
"BankerPartyID": "9EE7AE0A-4001",
"BankNumber": 4090466,
"BusinessPolicyID": 21,
"VersionNumber": "b5e8f11d-38cc-4861-9701-78e61a8f47d9",
"RepositoryName": null,
"IsBankToConvert": false,
"CreatedBy": null,
"ServerRootPath": null,
"SubmissionNumber": null,
"ReasonId": null,
"BankNotes": [], # Blank but coul also be an array of objects
},
"BankRequest": {
"BankHolder": null,
"BankTeam": null,
"PrimaryBanker": null,
},
"Customers": [{
"Name": "Dave"
"Phone": "555-555-5555"
}, {
"Name": "Bob"
"Phone": "555-555-5555"
}
],
"CurrentBankContract": {
"BankHolder": {
"BankHolderID": 1303164,
"SubscribingBankers": [{
"ElementGUID": "hihrwigohw-923489709724-jkflnanf3",
"ContractBankID": 1257638,
}, {
"ElementGUID": "4545ojoj-923489709724-jkflnanf3",
"ContractBankID": 1257456,
}
],
"BankNew": false,
"BankID": 585263,
},
"BankerTeam": {
"ContractBankerTeamMemberID": 5432605,
"Type": 1,
"SubscribingBanker": {
"ElementGUID": "45363-gsgsfdr-34525",
"ContractBankComponentID": 1257638,
},
"BankID": 585263,
}
}
}
I would need to map SomeViewModel and all of its contents. Now for an attribute like BankNotes, while it is an attribute to the Bank class it really is an array of type BankNote. So instead of a class named BankNotes I would have a class called BankNote and looking to map that part of it so that BankNotes can be an array of type BankNote and have access to all methods in the BankNote class. Anyway to map complex JSON to my own Ruby class?
As I understood you, your goal is parse json to object?
Here's your json(edited):
{
"Bank": {
"ID": 585263,
"BankName": "First Bank of CA",
"Drawer": null,
"LockDate": "2020-02-24T08:45:13.507",
"BankerPartyID": "9EE7AE0A-4001",
"BankNumber": 4090466,
"BusinessPolicyID": 21,
"VersionNumber": "b5e8f11d-38cc-4861-9701-78e61a8f47d9",
"RepositoryName": null,
"IsBankToConvert": false,
"CreatedBy": null,
"ServerRootPath": null,
"SubmissionNumber": null,
"ReasonId": null,
"BankNotes": []
},
"BankRequest": {
"BankHolder": "Hello, I'm bankholder from JSON!",
"BankTeam": null,
"PrimaryBanker": null
},
"Customers": [{
"Name": "Dave",
"Phone": "555-555-5555"
}, {
"Name": "Bob",
"Phone": "555-555-5555"
}],
"CurrentBankContract": {
"BankHolder": {
"BankHolderID": 1303164,
"SubscribingBankers": [{
"ElementGUID": "hihrwigohw-923489709724-jkflnanf3",
"ContractBankID": 1257638
}, {
"ElementGUID": "4545ojoj-923489709724-jkflnanf3",
"ContractBankID": 1257456
}],
"BankNew": false,
"BankID": 585263
},
"BankerTeam": {
"ContractBankerTeamMemberID": 5432605,
"Type": 1,
"SubscribingBanker": {
"ElementGUID": "45363-gsgsfdr-34525",
"ContractBankComponentID": 1257638
},
"BankID": 585263
}
}
}
Code that parses JSON to object:
require "json"
require "hashie"
file = File.read("example.json")
hash = JSON.parse(file, object_class: OpenStruct)
json_object = Hashie::Mash.new hash
json_object.BankRequest.BankHolder #=> "Hello, I'm bankholder from JSON!"
What i did here:
Readed item by File class
Parsed JSON to OpenStruct and
Created object from hash
Outputed value
As you can see - json_object is a Class with self methods.
Every key is self method that can contain another self methods e.t.c

How to convert json objects to json array in flutter

This is my json response data. I would like to display this data in listview using map but i dont know how to convert the objects of objects to array of data.
{
"success": true,
"data": {
"addresses": {
"abc": {
"address_id": "121",
"firstname": "Demo",
"lastname": "User",
"company": "Demo Company name",
"telephone": "1-541-754-3011",
"address_1": "Demo",
"address_2": "test address",
"postcode": "3333",
"city": "Berlin",
"zone_id": "1256",
"zone": "Berlin",
"zone_code": "BER",
"country_id": "81",
"country": "Germany",
"longitude": "",
"lattitude": "",
"iso_code_2": "DE",
"iso_code_3": "DEU",
"address_format": "{company}\r\n{firstname} {lastname}\r\n{address_1}\r\n{address_2}\r\n{postcode} {city}\r\n{country}",
"custom_field": null
}
}
}
}
I assume you want to display dynamic keys (eg: abc) inside addresses object. For this, you need to iterate through addresses object for keys and values.
//json you provide
addresses = json["data"]["addresses"];
addresses.forEach((final String key, final value) {
//here key will be abc & value will be json object
//you can add key or value to a different list and use for list rendering later
});
You can use JSON to dart tool, which is available online for free.
Paste your JSON to left panel and select dart language from upper right corner,
You will get your dart class code, in which you can use methods like .toMap() and .toJson(),
This can be very helpful for huge JSON data.

Custom attributes on a user delta call to the Microsoft Graph

I have some custom attributes configured to sync with an on-premise Active Directory. These attributes are syncing correctly and can be accessed via the following call to the Microsoft Graph.
https://graph.microsoft.com/v1.0/users?$select=id,displayName,givenName,surname,mail,jobTitle,department,companyName,mobilePhone,businessPhones,officeLocation,accountEnabled,extension_<GUID_REMOVED>_ipPhone,extension_<GUID_REMOVED>_division
{
"id": "<GUID_REMOVED>",
"accountEnabled": true,
"businessPhones": [],
"companyName": "Foobar",
"department": "IT",
"displayName": "Foo Bar",
"givenName": "Foo",
"jobTitle": "Labourer",
"mail": "foo.bar#foobar.com",
"mobilePhone": null,
"officeLocation": "Site",
"surname": "Foo",
"extension_<GUID_REMOVED>_division": "Group"
}
If I make the same call using the delta query
https://graph.microsoft.com/v1.0/users/delta?$select=id,displayName,givenName,surname,mail,jobTitle,department,companyName,mobilePhone,businessPhones,officeLocation,accountEnabled,extension_<GUID_REMOVED>_ipPhone,extension_<GUID_REMOVED>_division
{
"accountEnabled": true,
"businessPhones": [],
"companyName": "Foobar",
"department": "IT",
"displayName": "Foo Bar",
"givenName": "Foo",
"jobTitle": "Labourer",
"mail": "foo.bar#foobar.com",
"mobilePhone": null,
"officeLocation": "Site",
"surname": "Bar",
"id": "<GUID_REMOVED>"
}
The custom attributes are not shown in the result.
Can anyone help? Is there a reason for this or is it a bug?
This is a limitation of the Delta query. From the Known Issues documentation:
Delta query
OData context is sometimes returned incorrectly when tracking changes to relationships.
Schema extensions (legacy) are not returned with $select statement, but are returned without $select.
Clients cannot track changes to open extensions or registered schema extensions.

Resources