0

I have been trying to export multiple data fields from a single json file using powershell, and trying to place them nicely into an excel document. We basically have multiple data fields in each json file that are the same that contain contact information, and we are trying to export a list of that data to place into a new record system.

The flow is as follows: Export ClientID, ContactInfo, CustomerWebsite from each json object (BUT some have multiple entries, its archaic) to an excel CSV that lists File Name | ClientID, ContactInfo, CustomerWebsite.

I have been using the following code block in powershell to do it manually per each field I am trying to export >

Select-String -Path .\*.json -Pattern 'ClientID' | Select-Object -Property Filename,Line | Export-Csv "C:\Users\User\appdev\powershell-scripts\ClientID.csv" 

This exports the data in such a fashion:

exported data

Really looking for a way to stream line this into one call, and one singular output file so I can automate this. Ive looked everywhere. I am open to using python instead of powershell, Powershell is just something I know a lot better.

EDIT:

I have tried to use json psobject properties, but an running into issues as well.

Running

$json = (Get-Content "test.json" -Raw) | ConvertFrom-Json
$json.psobject.properties.name

Will only output the first line of the code, which is

sfg_ping::qa::standard_sp_connections

Any sub tag,object listed under that data seemingly isnt accessible by the psobject options. I am not sure if I am doing it incorrectly or what.

Ben S
  • 29
  • 4

0 Answers0