Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
bottos
Frequent Visitor

Trouble converting list into text (JSON and Azure Cognitive Services)

Hi. I am not sure what I am doing wrong, so any help will be greatly appreciated. I am using the Azure Cognitive Services to translate a column with text. To do that, I have created a function as following:
 
(input as text) =>
 
let
apikey = apiKey,
headers = [#"Ocp-Apim-Subscription-Key" = apiKey, #"Content-type" = "application/json"],
endpoint = "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=pt",
 
// JSON body
jsonbody = "[{ ""text"": """ & input & """ }]",
bytesbody = Text.ToBinary(jsonbody),
 
// Call the API
bytesresponse = Web.Contents(endpoint, [Headers = headers, Content = bytesbody]),
 
// Parse the JSON data
jsonresponse = Json.Document(bytesresponse),
//translation = jsonresponse,
#"Expanded Translations" = Table.ExpandListColumn(jsonresponse, "Translations"),
#"Expanded Translations1" = Table.ExpandRecordColumn(#"Expanded Translations", "Translations", {"translations"}, {"Translations.translations"}),
#"Expanded Translations.translations" = Table.ExpandListColumn(#"Expanded Translations1", "Translations.translations"),
#"Expanded Translations.translations1" = Table.ExpandRecordColumn(#"Expanded Translations.translations", "Translations.translations", {"text", "to"}, {"Translations.translations.text", "Translations.translations.to"})

in
#"Expanded Translations.translations1"
 
When I invoke the column, I get the following error:
 
Expression.Error: We cannot convert a value of type List to type Table.
Details:
Value=[List]
Type=[Type]
 
However, if I comment from the line #"Expand Translations", replace "in" with translation, I am able to expand the rows until I get the proper values.
 
As a complement, when I post to the API with Postman, the format I am sending is:
 
[
{"text":"Test String 1"},
{"text":"Test String 2 "}
]
 
And the answer back is:
 
[
{
"translations": [
{
"text": "Sequência de teste 1",
"to": "pt"
}
]
},
{
"translations": [
{
"text": "Sequência de teste 2 ",
"to": "pt"
}
]
}
]
 
So, again, any help would be greatly appreciated. Thanks.
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

seems to work ok?

 

let
    Source = Json.Document("[
{
""translations"": [
{
""text"": ""Sequência de teste 1"",
""to"": ""pt""
}
]
},
{
""translations"": [
{
""text"": ""Sequência de teste 2 "",
""to"": ""pt""
}
]
}
]"),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"translations"}, {"translations"}),
    #"Expanded translations" = Table.ExpandListColumn(#"Expanded Column1", "translations"),
    #"Expanded translations1" = Table.ExpandRecordColumn(#"Expanded translations", "translations", {"text", "to"}, {"text", "to"})
in
    #"Expanded translations1"

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

seems to work ok?

 

let
    Source = Json.Document("[
{
""translations"": [
{
""text"": ""Sequência de teste 1"",
""to"": ""pt""
}
]
},
{
""translations"": [
{
""text"": ""Sequência de teste 2 "",
""to"": ""pt""
}
]
}
]"),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"translations"}, {"translations"}),
    #"Expanded translations" = Table.ExpandListColumn(#"Expanded Column1", "translations"),
    #"Expanded translations1" = Table.ExpandRecordColumn(#"Expanded translations", "translations", {"text", "to"}, {"text", "to"})
in
    #"Expanded translations1"

Thank you. Now I see what I was doing wrong.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.