Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Json.FromValue: Convert Data to JSON

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Json.FromValue is a Power Query M function that takes any value—a record, list, table, number, text, or logical—and returns a JSON text string representing that value. You use it when you need to send data to a web API, store structured data as text, or embed a JSON payload inside a query. The function is available in Power Query inside Excel, Power BI Desktop, and Power BI dataflows; it is not available in Power Query Online for all connectors, so check your environment if a step fails. No add-ins or extra tools are required, but you should be comfortable opening the Power Query Editor and writing a small M expression.

What You'll Need

  • Excel (Microsoft 365 or a version with Power Query), Power BI Desktop, or another host that includes the Power Query Editor.
  • A query or table of data you want to convert, or a blank query to test with.
  • Basic familiarity with the Power Query Editor: the formula bar, the Advanced Editor, and the Applied Steps list.
  • Optional: a target that accepts JSON, such as a web API endpoint, if you plan to send the result.

Menu labels and the exact location of buttons can differ slightly by version, device, and region. The steps below describe the desktop Power Query Editor in Excel and Power BI; the mobile apps do not include the Power Query Editor.

Step-by-Step

  1. Open the Power Query Editor. In Excel, select a cell in your data and go to Data > From Table/Range. In Power BI Desktop, use Home > Transform data. If you only want to test the function, create a blank query: in Excel use Data > Get Data > From Other Sources > Blank Query; in Power BI use Home > New Source > Blank Query.
  2. Decide what value you want to convert. Json.FromValue accepts any M value. Common inputs are a record (a set of named fields), a list (an ordered set of values), a table, or a single scalar such as a number or text. The output is always a text string containing JSON.
  3. Write a simple test expression. Open the formula bar or the Advanced Editor and enter a query such as: This returns a JSON object with the keys Name and Devices. Confirm the result appears as text, not as a table.
  4. Convert a list. Replace the record with a list, for example: Json.FromValue({1, 2, 3}) The result is the JSON array [1,2,3]. Lists become arrays; records become objects; text becomes a quoted JSON string.
  5. Convert a table. If your query is named Sales, you can write Json.FromValue(Sales). A table is converted to a JSON array of objects, one object per row, using the column names as keys. Make sure column names are unique and contain no characters that would confuse downstream systems.
  6. Handle dates and other types. Json.FromValue converts dates, times, and datetimes to ISO 8601 text strings. Binary values are not supported and will raise an error; convert binary to text (for example with Base64 encoding) before calling the function if you need to include it.
  7. Use the result. If you are sending the JSON to an API, reference the step that contains the Json.FromValue output in a Web.Contents call. If you are storing it, load the query to a cell, a file, or a database column that accepts text. The output is plain text, so it can be concatenated or passed as a parameter.
  8. Name and document the step. Rename the query and the applied step so the purpose is clear, for example "JSON payload". This matters when other people maintain the workbook or report.

Common Mistakes

  • Expecting a table back. Json.FromValue returns text. If you need to parse JSON back into a table, use Json.Document instead.
  • Passing a binary value. Binary columns cause an error. Convert them to text first.
  • Assuming column order is preserved. JSON objects are unordered; do not rely on key order when the JSON is consumed elsewhere.
  • Forgetting that null becomes JSON null. Null values are preserved as null in the JSON, which some APIs reject. Replace nulls with empty strings or omit the field if the target requires it.
  • Using non-text keys. Record field names must be text. If you build a record dynamically, convert keys to text first.
  • Ignoring encoding. Special characters such as quotes and backslashes are escaped automatically. Do not manually escape them again, or the receiving system will see doubled escapes.

Tips

  • Test with a small record before converting a large table; the output is easier to inspect and errors are clearer.
  • Use Json.FromValue(..., [Encoding = TextEncoding.Utf8]) if you need a specific text encoding for the output.
  • Combine Json.FromValue with Text.Combine when you need to build a payload from several pieces.
  • Keep the JSON step near the end of the query so upstream changes do not break the structure unexpectedly.
  • If an API expects a specific date format, convert dates to text yourself with Date.ToText before building the record.

Troubleshooting

If the function returns an error, read the message in the formula bar or the query diagnostics window. The most common cause is an unsupported type, usually binary or a function value. Convert or remove that column and try again. If the query loads but the JSON looks wrong, check for nulls, duplicate column names, and unexpected type conversions such as numbers stored as text. If the receiving API rejects the payload, compare the output against the API documentation: key names, date formats, and whether the API expects an object or an array are frequent mismatches. If the step is slow on a large table, reduce the columns to only those needed before calling Json.FromValue. If the function is not recognised, confirm you are in the Power Query Editor and not in a regular worksheet formula; Json.FromValue is an M function, not an Excel function.

Frequently Asked Questions

What does Json.FromValue return?

It returns a text value containing JSON. Records become objects, lists become arrays, and tables become arrays of objects.

Can I convert JSON back into a table?

Yes, use Json.Document to parse a JSON text string into an M value, then expand it into a table.

Does Json.FromValue work with dates?

Yes. Dates, times, and datetimes are converted to ISO 8601 text strings. Convert them manually if the target needs another format.

Why do I get an error with a binary column?

Binary values are not supported. Encode them as text, for example with Base64, before calling the function.

Is Json.FromValue available in Power Query Online?

It is available in the Power Query Editor in Excel and Power BI Desktop. Availability in other hosts can vary, so check the function list in your environment.

Can I control the output encoding?

Yes, pass the optional Encoding option, such as TextEncoding.Utf8, in the second argument.