Question: I was trying to store a json string in local storage and retrieving the value in another function but its not working as expected 

For storing 

```
 var data = '{"history":['+'{"keyword":"'+key+'","msg":"'+msg+'","ver":"'+ver+'"}]}';   
             localStorage.setItem("history",JSON.stringify(data));

```

For retriving 

```
var historydata = JSON.parse(localStorage.getItem("history"));

```

tried to use the historydata.length and its showing 57 (its considering json array as a single string and showing its length ) I want the array size

Answer: 
The variable you are trying to store is already a json encoded string. You can not `stringify` it again.

You can drop those `'` and reformat the json, then it would be a normal json, then you can call `stringify` on it.

```
var data = {"history":[{"keyword":key,"msg":msg,"ver":ver}]};
localStorage.setItem("history", JSON.stringify(data));

```

To get the length of the array after retrieve:

```
var historydata = JSON.parse(localStorage.getItem("history"));
console.log(historydata.history.length);

```
You have already a JSON string. After JSON.stringify you get a string from a string.

The array size is one, because the content in one object.

```js
var key = 'KEY', msg = 'MSG', ver = 'VER',
    data = '{"history":[' + '{"keyword":"' + key + '","msg":"' + msg + '","ver":"' + ver + '"}]}',
    obj = JSON.parse(data);
document.write(obj.history.length + '<br>');
document.write('<pre>' + JSON.stringify(obj, 0, 4) + '</pre>');
```

Maybe you consider a better use of object, like an object literal:

```js
var key = 'KEY', msg = 'MSG', ver = 'VER',
obj = { history: [{ keyword: key, msg: msg, ver: ver }] };   
document.write('<pre>' + JSON.stringify(obj, 0, 4) + '</pre>');
```