Surya
Surya

Reputation: 638

Json Parsing in Node Js : Appending the Key: value in front of the Json

I have a Json which has so many lines of code. It has a time stamp that can distinguish it from other Json's. I need to take out that time stamp and append it in front of the Json itself. I do not know how to proceed.

For Json. Take any Json with time stamp.

Upvotes: 0

Views: 27

Answers (1)

DevAlien
DevAlien

Reputation: 2476

Assuming this is one of your jsons

{"name": "test", "ts": 18928938}

You can simply get the ts, append to another json and then remove the ts if you don't need it.

var result = {};
var json1 = {"name": "test", "ts": 18928938};
result[json1.ts] = json1;
remove result[json1.ts].ts; // This is if you want to remove the original ts

Upvotes: 2

Related Questions