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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.