jimothy.tutle
jimothy.tutle

Reputation: 23

What is the best way to interpret a Python string of a dictionary in powershell?

My input is the following string, describing a Python dict (of dicts), and I would like to convert it into a powershell hashtable. How should I proceed?

{'Animals': {'Canine': ['Dog', 'Wolf'], 'Feline': 'Cat'}, 'Fruits': {'Good':['Apple','Orange'], 'Bad': ['Durian']}}

Is there a library out there that could get this as a string input and return a hashtable object? Thanks!

Upvotes: 1

Views: 213

Answers (1)

Philip Meholm
Philip Meholm

Reputation: 391

powershell have the ability to convert items from json to psobjects.

powershell 7 have added the ability to even convert it to hashtable:

"{'Animals': {'Canine': ['Dog', 'Wolf'], 'Feline': 'Cat'}, 'Fruits': {'Good':['Apple','Orange'], 'Bad': ['Durian']}}"|ConvertFrom-Json -AsHashtable

Upvotes: 2

Related Questions