// Here is an initial JSON object to work with
var originalJson = {
"rows": [{
"ID": 123,
"Data": 430910,
"VersionNum": 0,
"RowSeqNum": 1,
"IterationNum": 1,
"FirstName": "Aqwemara",
"LastName": "Seweqweebi",
"Location": "CweAN",
"Role": "Site",
"In_Out": "Internal",
"Editor": "User1",
"Edit_Date": "2015%2D02%2D25T15%3A30%3A47%2E883Z"
}]
};
// Array containing keys for the new JSON
var keyResponse = [];
keyResponse.push("FirstName", "LastName", "Location", "Role", "Editor", "Edit_Date");
var updatedResponse = [];
$(document).ready(function() {
$('.btn').click(function() {
updatedResponse.push(
for each(key in keyResponse[{
key: response[i].key
}]);
console.log(JSON.stringify(updatedResponse));
});
});
// Additional setup for the console output
var consoleLine = "<p class=\"console-line\"></p>";
console = {
log: function(text) {
$("#console-log").append($(consoleLine).html(text));
}
};
.console-line {
font-family: console;
margin: 2px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input class="btn" type="button" id="btn" value="Go!">
<div id="console-log"></div>
I am working on transforming the originalJson
, making changes to specific key-value pairs, and reconstructing a JSON based on entries in the keyResponse
array.
When rebuilding the object, I aim to include only select keys from the initial JSON structure.
Is it possible to use a loop within the updatedResponse.push
statement to achieve the desired outcome smoothly? Any suggestions for improvement?
Thank you!
JSFIDDLE : https://jsfiddle.net/b5m0nk67/5/