Forum Discussion
Ferna
2 years agoFrequent Visitor
Import values from a local json file
Hello all, I'm trying to extract some values from a local json file:
confPath = "C:\<path>",
configFile = File.Contents(confPath, BinaryEncoding.Base64) as binary,
configText = Binary.ToText(configFile, BinaryEncoding.Base64),
configJson = Json.Document(configText),
AuthUrl = Record.Field(configJson, "url") & "auth?",
the json is :
{
"other_field": "other_field",
"url": "http://localhost:1852/realms/local-development/protocol/openid-connect/"
}
from the powerBI I have a runtime error: [Expression.Error] "We cannot convert the value 0 to type Record". What is wrong here?
Ferna Maybe this?
let Source = Json.Document(File.Contents("C:\temp\testjson.json")), #"Converted to Table" = Table.FromRecords({Source}), #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"other_field", type text}, {"url", type text}}) in #"Changed Type"
4 Replies
- Greg_DecklerCommunity Champion
Ferna Maybe this?
let Source = Json.Document(File.Contents("C:\temp\testjson.json")), #"Converted to Table" = Table.FromRecords({Source}), #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"other_field", type text}, {"url", type text}}) in #"Changed Type"- FernaFrequent Visitor
It doesn't work, with same error. Also, if you not specify the encoding type, it does not compile: "UnpermittedResourceAccessException". I try also:
File.Contents(confPath, BinaryEncoding.Hex)but similar error "We cannot convert the value 1 to type Record"
- Greg_DecklerCommunity Champion
Ferna It works fine for me. I just took your json and pasted into Notepad and saved as testjson.json. I'm not understanding the binary encoding stuff you are doing. Is your json file not text? I would think it would be text.