Questions tagged [convertto-json]

31 questions
42
votes
3 answers

Unexpected ConvertTo-Json results? Answer: it has a default -Depth of 2

Why do I get unexpected ConvertTo-Json results, why do I get values like System.Collections.Hashtable and/or why does a round-trip ($Json | ConvertFrom-Json | ConvertTo-Json) fail? Meta issue Stackoverflow has a good mechanism to prevent duplicate…
iRon
  • 20,463
  • 10
  • 53
  • 79
13
votes
3 answers

ConvertTo-Json and ConvertFrom-Json with special characters

I have a file containing some properties which value of some of them contains escape characters, for example some Urls and Regex patterns. When reading the content and converting back to the json, with or without unescaping, the content is not…
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
9
votes
1 answer

Transform a list of strings to JSON array using jq

Having a list of strings (one per line) like str1 str2 ... how do I convert these into the JSON list ["str1", "str2", ...]?
bisgardo
  • 4,130
  • 4
  • 29
  • 38
3
votes
1 answer

Convert JSON array object to String in Powershell

I am working with a JSON like that looks like this: [ { "Ack": "no", "Rule": "dont", "Tags": [ "server" ], "Type": "blue" }, { "Ack": "no1", …
mr i.o
  • 952
  • 2
  • 10
  • 20
2
votes
3 answers

Powershell ConvertTo-Json from import-csv poor performance

I have a performance issue with the below Powershell script. I want to parse information from CSV file to JSON file. The performance of this conversion is very good when the CSV file size is small. But the execution is not completing/hang when I ran…
sridharnetha
  • 2,104
  • 8
  • 35
  • 69
2
votes
2 answers

How to Pass User Input to a JSON File using powershell

I am creating a PowerShell script using Convert To-JSON cmd and i achieved that using below $body = @{ devices = @( @{ credentials = @( @{ label…
karhtik
  • 506
  • 3
  • 15
2
votes
2 answers

Powershell - ConvertTo-Json hangs script

Evening all, I have a script block below to add a user to an application in OKTA. It runs perfectly if I define a user ($login) and run the script, however if I wrap the script block below in a ForEach loop it hangs indefinitely without proceeding…
2
votes
1 answer

How to properly format PSObject to pass to PUT method for InvokeRest Method

Below is the key value pairs I need to pass to the API. Dont know where Im going wrong $Body = @{ hostName = 'null' hostOperatingSystem = 0 optionalFilter1 = 'null' optionalFilter2 = 'null' description …
Naldo Ash
  • 21
  • 3
2
votes
1 answer

ConvertTo-Json in object with array as property value

In Windows Powershell I have a simple Invoke-SqlCmd query which returns the following table: ID Text -- ---- 1 FOO 2 BAR 3 SPAM Piping it to | ConvertTo-Json -Depth 1 yields the following result: [ { "RowError": "", …
Fry Simpson
  • 1,125
  • 11
  • 15
2
votes
2 answers

PowerShell ConvertTo-JSON with multiple arrays

I'm trying to convert data to JSON as input for a REST API. The challenge I have is that the data should consist of multiple depths (For a lack of better words). The code I'm using now is: (@{name = "Contoso"; all_assets = "false";…
2
votes
6 answers

how to convert pdf file to excel file using python

I want to convert a pdf file into excel and save it in local via python. I have converted the pdf to excel format but how should I save it local? my code: df = ("./Downloads/folder/myfile.pdf") tabula.convert_into(df, "test.csv",…
Yuvraj Singh
  • 37
  • 1
  • 1
  • 6
2
votes
0 answers

How do I preserve Enums as 'Strings' in ConvertTo-Json cmdlet?

ConvertTo-Json cmdlet in PowerShell core has a parameter EnumsAsStrings which allows JSON to have string representations instead of integer for Enums. There is no such parameter in Windows Powershell. What will be a solution for complex objects for…
Gregory Suvalian
  • 3,566
  • 7
  • 37
  • 66
1
vote
1 answer

Convert dataframe columns into dict and save it as json file, with columns name as dict key and row values as dict values

I have a pandas dataframe as below : device_id user_id level d_id1 u_id1 1 d_id1 u_id2 -1 d_id1 u_id3 1 d_id2 u_id100 -1 d_id3 u_id100 1 d_id3 u_id4 1 I want to convert it into a list of dictionaries depend on columns and rows…
Man Fan
  • 35
  • 1
  • 6
1
vote
1 answer

Issue with PowerShell ConvertTo-Json adding un-printable characters to beginning of file

I am having a problem with a PowerShell ConvertTo-Json command. The resulting file has two non-printable characters as the first to characters of the file. Using Format-Hex, the return values are: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D…
1
vote
2 answers

Powershell batch of commands response into JSON

I'm trying to capture a list of users and groups on my windows host. I can capture the user and groups info and assign them to varaibles $users and $groups with the following commands: $groups=$(Get-WmiObject win32_group | Select Name | Sort…
Coder Jones
  • 93
  • 1
  • 4
1
2 3