Imagine a scenario where a client makes a GET request and the response is in JSON format similar to the following:
var result = {
"enabled": true,
"state": "schedule",
"schedules": [
{
"rule": {
"start": "2014-06-29T12:36:26.000",
"end": "2014-06-29T12:36:56.000",
"recurrence": [
"RRULE:FREQ=MINUTELY"
]
},
"wifi_state_during_rule": "disabled",
"end_state": "enabled"
}
],
"calculated_wifi_state_now": "disabled",
"time_of_next_state_change": [
"2014-07-08T18:56:56.000Z",
"2014-07-08T18:57:56.000Z"
]
};
This example stores the JSON response in a variable named "result". The regex expression used here is:
checkPattern = /"\w+\"(?=:)/ // Extracts all keynames "keyname": ...
The idea is to extract keynames within the object or array structure of the JSON data. Since keynames are defined as "keyname": in JSON, that's why this specific regex expression is being utilized.
Although a recursive function was considered for this task, it did not yield the desired results.