So why don't you simply use a key-value literal?

var params = {
    'slide0001.html': 'Looking Ahead',
    'slide0002.html': 'Forecase',
    ...
};

return params['slide0001.html']; // returns: Looking Ahead
Answer from Crozin on Stack Overflow
Discussions

How do I process the key-value pairs in an array of JSON objects?
Keep in mind that the cmdlet ConvertTo-Json returns the string representation of the data. The statement [System.IO.DriveInfo]::GetDrives() already returns the object representation of the collection, so you can loop over the return value from that instead. More on reddit.com
🌐 r/PowerShell
14
13
April 20, 2022
Getting an array of specific key/value pairs from JSON file
Beginner here - I'd like to create an array for my cities of the world type ahead project from a JSON file. I've fetched the data, now I would like to extract 2 key/value pairs (called name/country... More on stackoverflow.com
🌐 stackoverflow.com
Key value pairs using JSON - javascript
Is there a way to handle data structures using JSON object in a way of Key/ Value pairs? If so can some one elaborate how to access associated value object from the key Assume that I have More on stackoverflow.com
🌐 stackoverflow.com
jquery - How to create key value pair JSON array - Stack Overflow
The format you're trying to create is not syntactically correct, you can't have key/value pairs in an array. More on stackoverflow.com
🌐 stackoverflow.com
May 23, 2017
🌐
ServiceNow Community
servicenow.com › community › developer-forum › parse-json-array-to-get-key-value-pair › m-p › 2469890
Solved: parse json array to get key value pair - ServiceNow Community
February 7, 2023 - Hello All, I am trying to populate key-value pair from multi row variable set of incident table. With below code I am getting JSON array var gr = new GlideRecord('incident'); gr.addQuery('number=INC0001164'); gr.query(); if (gr.next()) { var mrvs = gr.variables.employee_details; gs.print(mrvs); } ...
🌐
Squarespace
developers.squarespace.com › what-is-json
JSON
Everything inside of the curly brackets is part of the object. We already learned a value can be an object. So that means "foo" and the corresponding object are a key/value pair. ... The key/value pair "bar" : "Hello" is nested inside the key/value pair "foo" : { ... }. That's an example of ...
🌐
RestfulAPI
restfulapi.net › home › json › json syntax
JSON Syntax - REST API Tutorial
November 3, 2023 - A JSON object looks something like this: { "color" : "Purple", "id" : "210", "composition" : { "R" : 70, "G" : 39, "B" : 89 } } Data can also be nested within the JSON by using JavaScript arrays that are passed as a value using square brackets ...
🌐
DEV Community
dev.to › tooleroid › master-json-key-value-pairs-a-complete-guide-59b
Master JSON Key-Value Pairs: A Complete Guide - DEV Community
December 23, 2024 - Let's break down how these pairs work. For more on JSON schema, check out our guide on json schema definition: ... JSON values come in different flavors. For more on comparing data formats, see our guide on json vs xml. Here's your menu of options: { "string_example": "Hello, World!", "number_example": 42, "boolean_example": true, "array_example": [1, 2, 3], "object_example": { "nested": "value" }, "null_example": null }
🌐
Matthewb
matthewb.id.au › csv › key-value-pairs-to-javascript-json-array.html
Key Value Pairs into Javascript JSON Array
July 22, 2018 - Use key value pairs like: MyArray[0].key + " " + MyArray[0].value; ... var MyArray = [ {"key":"key1", "value":"value1"}, {"key":"key2", "value":"value2"}, {"key":"key3", "value":"value3"} ]; Ctrl A = Select All, Ctrl C = Copy, Ctrl V = Paste.
Find elsewhere
🌐
Harvard
cscie12.dce.harvard.edu › lecture_notes › 2021-spring › 20210413 › slide5.html
Slide 5 - JS Data Structures - array and "object" (key/value pair) § Session 11 - JavaScript, Part 4
JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. ... A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
🌐
Micro Focus
microfocus.com › documentation › silk-performer › 195 › en › silkperformer-195-webhelp-en › GUID-6AFC32B4-6D73-4FBA-AD36-E42261E2D77E.html
JSON Object Structure - Micro Focus
A key-value pair consists of a key and a value, separated by a colon (:). The key is a string, which identifies the key-value pair. The value can be any of the following data types: { } //Empty JSON object { “StringProperty”: “StringValue”, “NumberProperty”: 10, “FloatProperty”: 20.13, “BooleanProperty”: true, “EmptyProperty”: null } { “NestedObjectProperty”: { “Name”: “Neste Object” }, “NestedArrayProperty”: [10,20,true,40] }
🌐
Reddit
reddit.com › r/powershell › how do i process the key-value pairs in an array of json objects?
r/PowerShell on Reddit: How do I process the key-value pairs in an array of JSON objects?
April 20, 2022 -

Hi, I'm new to powershell (just started yesterday).

I am trying to make a script that gets the disk info in a JSON format. So far I have

$disk_list = @([System.IO.DriveInfo]::GetDrives() | ConvertTo-Json -Depth 1)

This returns:

[
    {
        "Name":  "C:\\",
        "DriveType":  3,
        "DriveFormat":  "NTFS",
        "IsReady":  true,
        "AvailableFreeSpace":  141158105088,
        "TotalFreeSpace":  141158105088,
        "TotalSize":  171220922368,
        "RootDirectory":  "C:\\",
        "VolumeLabel":  ""
    },
    {
        "Name":  "D:\\",
        "DriveType":  5,
        "DriveFormat":  null,
        "IsReady":  false,
        "AvailableFreeSpace":  null,
        "TotalFreeSpace":  null,
        "TotalSize":  null,
        "RootDirectory":  "D:\\",
        "VolumeLabel":  null
    }
]

Now I want to be able to go through each object in the array, and then through each key-value pair, and alter the key slightly.

I have tried several foreach loops, but they don't seem to be working. Even something as simple as:

ForEach ($obj in $disk_list) {
    echo $obj
    echo "*********************************"
}

is not doing what I expected it to. It just prints the whole $disk_list array with one line of "**********************" at the end, instead of printing each object followed by a "**********************".

My end goal is to achieve something along the lines of (in pseudocode):

ForEach ($obj in $disk_list) {
    ForEach ($kv_pair in $obj) {
        $key = lowercase($kv_pair.Key)
        kv_pair.Key = "{#" + $key + "}"
        # So if the key used to be "Name", it should be transformed to "{#Name}"
    }
}

How can I achieve this in powershell?

🌐
Baeldung
baeldung.com › home › json › get a value by key in a jsonarray
Get a Value by Key in a JSONArray | Baeldung
January 8, 2024 - Learn how to parse a JSONArray to get all the mapped values for a given key.
🌐
Kii Cloud
docs.kii.com › en › guides › cloudsdk › android › managing-data › json-document › set-key-value
Setting a Key-value Pair - Kii Documentation
Use the values in the "Stored key-value pair in the JSON format" column in the following table as reference when checking data in the data browser in the developer portal and referencing data from another platform.
🌐
DigitalOcean
digitalocean.com › community › tutorials › an-introduction-to-json
An Introduction to JSON | DigitalOcean
JSON — short for JavaScript Object Notation — is a format for sharing data. As its name suggests, JSON is derived from the JavaScript programming language, b…
🌐
Kii Cloud
documentation.kii.com › en › guides › cloudsdk › android › managing-data › json-document › set-key-value
Setting a Key-value Pair
Use the values in the "Stored key-value pair in the JSON format" column in the following table as reference when checking data in the data browser in the developer portal and referencing data from another platform.
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
How to Display Key and Value Pairs from JSON in ReactJS | Pluralsight
April 24, 2024 - Here comes the most tricky part of the JSON name-value pair rendering. React does not directly allow us to render any object in JSX. If we mistakenly do that, it will result in the following error: Objects are not valid as a React child (found: object with keys { a, b, c }). If you meant to render a collection of children, use an array ...
🌐
Microsoft Power Platform Community
powerusers.microsoft.com › t5 › Building-Flows › Help-Parseing-dynamic-json-object-array-to-get-key-value-pairs › td-p › 959346
Forums | Microsoft Power Platform Community
June 21, 2021 - Quickly search for answers, join discussions, post questions, and work smarter in your business applications by joining the Microsoft Dynamics 365 Community.