Created
March 21, 2023 00:23
-
-
Save SimonStorlSchulke/1db850508848d7c300859143d6db4954 to your computer and use it in GitHub Desktop.
Replace mutiple json values at the given key-array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replaceJsonArguments(jsonText: string, keyValues: Map<string[], string>) { | |
let jsonObj = JSON.parse(jsonText); | |
for (let [key, value] of keyValues) { | |
var currentObj = jsonObj; | |
for (var i = 0; i < key.length - 1; i++) { | |
currentObj = currentObj[key[i]]; | |
} | |
currentObj[key[key.length - 1]] = value; //ChatGPT is a genius... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FE: