JSON Input

PowerShell Output

What does the JSON to PowerShell converter do?

ConvertFrom-Json is great at runtime, but sometimes you want the data written into the script itself: a test case, a default config, a request body you'll tweak by hand. Paste JSON here and you get one assignment, $data = [pscustomobject]@{ ... }, with nested objects as [pscustomobject] literals and arrays as @( ... ) blocks. That's the same shape ConvertFrom-Json gives you, and the keys stay in their original order.

Strings are written in single quotes, so $5, backticks and $(...) are never expanded; a quote inside a string is doubled, and that includes the curly quotes PowerShell also treats as quote marks. Keys that aren't simple names, like first name or user-id, and keys that are PowerShell keywords such as end or param, are quoted too. See about_Quoting_Rules for why single quotes are the safe choice.

null becomes $null, booleans become $true and $false. Integers that fit in [long] are written as plain literals, exactly; bigger ones are written as [bigint]'89012405441020662461', because a bare literal that large would turn into a rounded [double]. Everything runs in your browser.

How to use it

The script updates as you type.

1

Paste JSON

Paste into the Input panel, Upload a .json or .txt file, or click Sample. Example input:

{"subscriberId":"SUB-1001","plan":"Unlimited 5G","dataUsage":45.2,"status":"active"}

Variable Name sets the variable ($data by default); characters PowerShell doesn't allow in a plain variable name become underscores. Not sure the JSON is valid? Check it with the JSON Validator.

2

Check the object

The Output panel shows the literal with four-space indentation. Each property sits on its own line, so no semicolons are needed.

3

Copy or download

Copy it or Download data.ps1, then dot-source it (. .\data.ps1) or paste it into your script. Pipe the object to ConvertTo-Json -Depth 10 to get JSON back.

Where this saves time

Pester test data

Paste a real API response and use the object as expected or mocked data in a Pester test, without keeping a separate JSON file next to it.

Request bodies for Invoke-RestMethod

Convert a sample payload, edit the values in PowerShell syntax, and send it with Invoke-RestMethod -Body ($data | ConvertTo-Json -Depth 10).

Default settings in a script

Embed default configuration right in an automation script, then merge in overrides from a file when one exists.

Seeing the shape of ConvertFrom-Json output

Because the output uses [pscustomobject] and @() just like ConvertFrom-Json, it doubles as a readable view of what you'll get back at runtime.

Common Questions

Why [pscustomobject] and not a hashtable?

A plain @{} hashtable doesn't keep key order and behaves differently from what ConvertFrom-Json returns. [pscustomobject]@{} keeps the order and gives you an object with properties, which is what most scripts expect. If you really want a hashtable, remove the [pscustomobject] prefix.

Which PowerShell versions does it work with?

The syntax works in Windows PowerShell 5.1 and PowerShell 7. We generate it by following the language rules; there is no PowerShell engine behind this page, so run it once before you rely on it.

Are special characters safe?

Yes. Strings are single-quoted, so nothing inside them expands, and embedded quotes are doubled. Newlines inside a value are kept as real line breaks inside the quotes, which PowerShell allows.

What happens to very large numbers?

Anything that fits in [long] stays a plain literal. Bigger integers are written as [bigint]'...' so every digit survives. Strings that only contain digits stay strings.

Is my JSON uploaded?

No. The script is generated by JavaScript in your browser and nothing is sent to a server. Input is capped at 256 KB.

Other JSON Tools You Might Need

Need the same data as a shell script or in another language?