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
How to make data in an array the keys of a JSON file?
I was processing some data and I have filtered the data to a point where I have stored the data which should be the keys of the JSON file I want to create into an array like this [ 'A', 'B', 'C', 'D', 'E' ] Now I want to set these array values as keys dynamically to create a JSON with other ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
February 14, 2023
JSON manipulation from key-value to array?
Hi all, I need to work on each key entry values (ean, image, name, …). I need an array to be able to call an api with the split node. I try some JS snippet without succes. Thanks for help More on community.n8n.io
🌐 community.n8n.io
1
0
August 2, 2021
What is the method to insert a value in a JSON object array?
I am trying to add a new key-value pair to objects inside a JSON array. How can I achieve this with JavaScript? Here’s a simplified example: let data = [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' } ]; // Add 'age' property to each object for (let obj of data) { obj.age = 25; } ... More on community.latenode.com
🌐 community.latenode.com
0
0
November 3, 2024
🌐
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); } ...
🌐
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?

🌐
Squarespace
developers.squarespace.com › what-is-json
What is JSON? — Squarespace Developers
"foo" : { "bar" : "Hello", "baz" : [ "quuz", "norf" ] } An object is indicated by curly brackets. 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" : { ... }. ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › an-introduction-to-json
An Introduction to JSON | DigitalOcean
August 24, 2022 - These objects and arrays will be passed as values assigned to keys, and may be comprised of key-value pairs as well. In the following users.json file, for each of the four users ("sammy", "jesse", "drew", "jamie") there is a nested JSON object passed as the value for each of them, with its own nested keys of "username" and "location" that relate to each of the users. Each user entry in the following code block is an example ...
Find elsewhere
🌐
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 ...
🌐
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 ... 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
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] }
🌐
W3Schools
w3schools.com › js › js_json_objects.asp
JSON Object Literals
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... JSON object literals are surrounded by curly braces {}. JSON object literals contains key/value pairs...
🌐
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 }
🌐
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 - In this tutorial, we’ll be using JSON-Java (org.json) library and learn how to process a JSONArray to extract value for a given key. If needed, we have available an introduction to this library. We’ll first start by adding the below dependency in our POM: <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20240303</version> </dependency> We can always find out the latest version of JSON-Java on Maven Central. A JSON message is usually comprised of JSON objects and arrays which may be nested inside one another.
🌐
Latenode
community.latenode.com › other questions › javascript
What is the method to insert a value in a JSON object array?
November 3, 2024 - Here’s a simplified example: let data = [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' } ]; // Add 'age' property to each object for (let obj of data) { obj.age = 25; } console.log(data); This modifies the existing objects by adding an ‘age’ ...
🌐
Kii Cloud
docs.kii.com › en › guides › cloudsdk › android › managing-data › json-document › set-key-value
Setting a Key-value Pair - Kii Documentation
Specify a key-value pair as arguments of the set() method. The specified key-value pair will be saved at the first level of the JSON document hierarchy.
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › 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 ...