(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to Read and Process JSON Files in PowerShell

João Barros 10 de July de 2026 4 min read

JSON files are everywhere: API responses, configuration files and data exports. Knowing how to read JSON files in PowerShell lets you turn that text into objects you can filter, change and save again — all with native cmdlets, without installing anything. Below is the full step by step, from loading the file to saving the result.

Prerequisites

  • Windows PowerShell 5.1 or PowerShell 7+ (the JSON cmdlets exist in both).
  • A sample JSON file saved on disk (we will use produtos.json).
  • Basic familiarity with the PowerShell console: opening the window and running commands.

Step 1: Prepare a sample JSON file

To follow along, create a file called produtos.json in your working folder with a few records. Each object represents a product with a name, price and stock. This is the file we will read and process.

[
  { "nome": "Teclado", "preco": 25.5,  "stock": 12 },
  { "nome": "Rato",    "preco": 15.0,  "stock": 0  },
  { "nome": "Monitor", "preco": 199.9, "stock": 5  }
]

Step 2: Read the file with Get-Content and ConvertFrom-Json

The first step is to read the file's text and convert it into PowerShell objects. Use Get-Content with the -Raw parameter to read the whole file as a single string, and pipe the result to ConvertFrom-Json.

$produtos = Get-Content -Path '.produtos.json' -Raw | ConvertFrom-Json
$produtos

The -Raw matters: without it, the file is read line by line and ConvertFrom-Json can fail on multi-line files. After this line, $produtos is a collection of objects that behave like any native object — you can even run $produtos | Get-Member to see the available properties.

Tip: if your JSON represents a single object (not a list), ConvertFrom-Json returns just one object. In that case you do not need to loop through a collection; access the properties directly.

Step 3: Access properties and filter data

Now that you have objects, you can reach each field with a dot. For example, $produtos[0].nome returns the name of the first product. To filter, use Where-Object; in the example below we keep only the products that still have stock.

# All names
$produtos.nome

# Only products with stock available
$comStock = $produtos | Where-Object { $_.stock -gt 0 }
$comStock | Select-Object nome, preco

Inside the filter, $_ represents the current object. You can combine conditions with -and and -or, and sort the result with Sort-Object preco, just as you would in a database query.

Step 4: Change values and save with ConvertTo-Json

After working with the data, you often want to save it again. Let's apply a 10% discount to each price and write the result to a new file with ConvertTo-Json.

foreach ($p in $produtos) {
    $p.preco = [math]::Round($p.preco - $p.preco / 10, 2)
}

$produtos |
    ConvertTo-Json -Depth 5 |
    Set-Content -Path '.produtos_com_desconto.json' -Encoding UTF8

Note the -Depth parameter. By default, ConvertTo-Json only converts 2 levels deep; with nested data, increasing -Depth avoids losing information. The -Encoding UTF8 ensures accents and special characters stay correct in the saved file.

Check the result

To confirm everything went well, read the generated file again and show the data in a table. If the number of products and the discounted prices appear as expected, the processing worked.

$verificar = Get-Content -Path '.produtos_com_desconto.json' -Raw | ConvertFrom-Json
$verificar | Format-Table nome, preco, stock
"Total de registos: $($verificar.Count)"

You should see the table with the three products and the already reduced prices. If you get a conversion error, check that the JSON is valid (braces and quotes properly closed) and that you used -Raw when reading the file.

Conclusion

With just two cmdlets — ConvertFrom-Json and ConvertTo-Json — PowerShell reads, transforms and saves JSON data without any external tools. From here you can wire these steps to API calls, automate recurring reports, or prepare files to load into a Data Warehouse. Which JSON file will you stop editing by hand next?