Q:

How to convert All json values to String without iteration

I have JSON in which all the values have to be changed to string. The values may be a number, boolean, undefined or null.
{
    "obj1": [{
        "n1": "n",
        "n2": 1,
        "n3": true
    },
    {
        "n1": "n",
        "n2": 1,
        "n3": null
    }]
}

The expected result is all the values should be formatted as a string.
Example:
{
    "obj1": [{
        "n1": "n",
        "n2": "1",
        "n3": "true"
    },
    {
        "n1": "n",
        "n2": "1",
        "n3": "null"
    }]
}

By iterating through the JSON object we can do this, but is there any simpler way to do this.

A:

You could take JSON.stringify with a replacer function  and check if the values is a number, then take a stringed value, or just the value.

var object = { obj1: [{ n1: "n", n2: 1, n3: true }, { n1: "n", n2: 1, n3: null }] },
    json = JSON.stringify(object, (k, v) => v && typeof v === 'object' ? v : '' + v);

console.log(json);
console.log(JSON.parse(json));

