Question: I have a scenario where many fields in JSON response that are coming as string (`"true"/"false"`).

Now I need to replace all of the values from `string` to `Boolean` in one shot via `Javascript`.

Sample:

```
{
    field1: "true",
    field2: "false"
}

```

Expected:

```
{
    field1: true,
    field2: false
}

```

This is a sample. My JSON response is very huge with many objects and arrays.

Answer: 
The [`JSON.parse` reviver parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Examples) can be used to exclude or modify values:

```js
var j = '{"field1":"true","field2":"false"}';

var o = JSON.parse(j, (k, v) => v === "true" ? true : v === "false" ? false : v);

console.log(o);
```
My version, does not modify source object, returns new object with parsed booleans:

```js
const object = {
  "test": "true",
  "test1": false,
  "test2": "false",
  "test3": 5,
}

console.log(parseBooleansInObj(object));

function parseBooleansInObj(object) {
  const newObject = { ...object };
  Object.keys(newObject)
    .forEach((objKey) => {
      let value = newObject[objKey];
      value = (value === 'true' ? true : value === 'false' ? false : value);
      newObject[objKey] = value;
    });
  return newObject;
}
```