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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Ferna
Frequent 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?

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community 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"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community 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"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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"

 

@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.

Greg_Deckler_0-1714660498470.png

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

File.Contents(<path>)

is not available when you are customizing a data connector (so not authorized to use). I accept as a solution because works in normal conditions.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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