#PowerPlatformTip 124: 'Recognize Plain Text File Formats'
TL;DR: “Get file content” (SharePoint, OneDrive for Business) infers the content type from the file extension. Text formats such as
.txt,.csv,.xmlor.htmlcome back as plain text and.jsonas a JSON object, sobody('Get_file_content')is usable directly. Binary files come back as an object with$content-typeand a base64$content. Strip a UTF-8 BOM before you parse CSV or JSON. It shows up afterbase64ToStringwhen Infer Content Type is No.
Update 31 October 2026: Clarified the BOM. With Infer Content Type set to Yes the CSV arrives as plain text. The BOM becomes visible after
base64ToStringwhen Infer Content Type is No, so remove it at that point.
💡 Challenge
You read a file in a flow and want to work with its text: split a CSV, parse a JSON configuration, search a log. Sometimes the output is readable text, sometimes it is a $content blob in base64, and the same expression fails on the other kind.
✅ Solution
Know what decides the output: the Infer Content Type setting of “Get file content” (on by default) maps the file extension to a content type. Text types are returned as a string, .json files as parsed JSON, everything else as a base64 object. Pick the expression that matches.
🔧 How It’s Done
1. Get the file
🔸 Add Get file content (SharePoint) or Get file content / Get file content using path (OneDrive for Business) and leave Infer Content Type set to Yes.
2. Text file: use the body directly
🔸 For .txt, .csv, .xml, .html and similar text formats the output is the text itself. A .json file comes back as parsed JSON: address the properties directly if the root is an object, select or loop over the elements if the root is an array (for example [{"name":"Alice"},{"name":"Bob"}]):
1
body('Get_file_content')
🔸 Example CSV, one array element per line:
1
split(body('Get_file_content'), decodeUriComponent('%0A'))
3. Binary or unknown type: decode $content
🔸 If the run output shows {"$content-type": "...", "$content": "..."} and the file contains text, decode the base64. For real binary files (PDF, images, ZIP) don’t decode: pass body('Get_file_content') unchanged to the next action (see FAQ 3):
1
base64ToString(body('Get_file_content')?['$content'])
🔸 This happens for extensions the service doesn’t map to a text type and when Infer Content Type is set to No.
4. Remove the BOM
🔸 Files saved as “UTF-8 with BOM” (Excel’s CSV UTF-8, many Windows editors) start with an invisible byte order mark. It becomes visible after base64ToString (Infer Content Type = No) and ends up in the first column name or makes json() fail. Remove it first:
1
2
3
4
5
// 1) Compose named Decoded, only when the body is the $content object (Infer Content Type = No):
base64ToString(body('Get_file_content')?['$content'])
// 2) remove a leading BOM only, keep the text otherwise:
if(startsWith(uriComponent(outputs('Decoded')), '%EF%BB%BF'), slice(outputs('Decoded'), 1), outputs('Decoded'))
🔸 Decode only when the body really is the $content object: text that already arrives as a string must not be decoded again, and string() on the object would serialize the object instead of decoding the file. The if(startsWith(...)) form removes the BOM only at the start of the text, not the same character elsewhere. It compares the URI-encoded text with %EF%BB%BF on purpose: a direct startsWith(text, decodeUriComponent('%EF%BB%BF')) returns true for every text in Power Automate and would cut the first character of files without a BOM. slice() also handles an empty file, where substring() fails (tested in a flow on 28 November 2026 with and without BOM, BOM in the middle, JSON, BOM only and an empty file). If the text is JSON, wrap the cleaned result in json() to get the parsed JSON value (an object or an array, depending on the root) again; keep CSV and other plain text as text.
🔸 Files in a legacy encoding such as Windows-1252 show umlauts and accents as �. Save them as UTF-8 at the source.
🎉 Result
Text files are processed directly, without a decoding step, and binary files are decoded only when needed. CSV headers and JSON parse cleanly because the BOM is gone.
🌟 Key Advantages
🔸 Simpler flows: no decoding action for text formats.
🔸 Predictable: the extension tells you which expression to use.
🔸 Robust parsing: removing the BOM prevents the classic “first column not found” error.
🎥 Video Tutorial
🛠️ FAQ
1. Which file formats come back as plain text?
Extensions that map to a text content type, for example .txt, .csv, .xml and .html. A .json file comes back as a JSON object. Check the run output once: readable text means plain text, a $content object means base64.
2. Do all connectors behave the same way?
The SharePoint and OneDrive for Business “Get file content” actions infer the type from the extension. Other connectors can return binary content regardless of the extension, so check the run output.
3. How do I handle formats that output as base64?
Use base64ToString(body('Get_file_content')?['$content']) for text content. For real binary files (PDF, images, ZIP), pass body('Get_file_content') unchanged to the next action, for example “Create file”.
📥 Download: CSV to JSON Office Script
Once Get file content hands you the CSV as text, pass it to a ready-made Office Script that returns a JSON array of objects, with delimiter detection and correct handling of quoted values. Download the script and setup guide.
🔗 Related Tips
- #PowerPlatformTip 125: Convert CSV to JSON, turn plain-text CSV into JSON with standard actions.
- #PowerPlatformTip 104: Efficient JSON Handling, process JSON payloads cleanly in flows.
This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).