As I searched through various resources on converting JSON into arrays using JavaScript, none of the results matched my specific requirements (outlined below).
I am in need of a RegEx that can transform JSON into an array containing all characters such as commas, curly brackets for objects, brackets for arrays, colons, escape characters, null values, etc., while disregarding any whitespace.
Pseudocode for the RegEx:
The RegEx should match any curly bracket character (both open and closed), any word enclosed in parenthesis, colon character, comma character, bracket character (both open and closed), numbers, and null values.
Sample Input String (JSON will vary)
{
"hello":"world",
"\"foo\"":"bar",
"my_object":{
"my_array": [
1,
null,
{ "my_key":"my_value" }
]
}
}
Desired Output From RegEx
[
"{", "hello", ":", "world", ",", "\"foo\"", ":", "bar", ",", "my_object",":", "{", "my_array", ":", "[", 1, ",", null, ",", "{", "my_key", ":", "my_value", "}", "]", "}", "}"
]
Appreciate your help!