Reputation: 394
I am a beginner programmer trying to convert JSON array property value from arrays to keys.
From
..,"searchResult":[{"itemId":["123"],"title":["abc"],..}]
to
..,"searchResult":[{"itemId":"123","title":"abc",..}]
Full original JSON result here with search result highlighted
the JSON array is being received in this code
//function to retrieve JSON arrays
function _cb_findItemsByKeywords(root) {
//Navigates and assigns variable "items" into the property, item
var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
var a = (items);
//assigned variable a to the array
}
Question: How do I remove the square brackets and check my array a?
EDIT:
Sorry for the confusion, My goal is to combine this array with [..]
with another array without [..]
before appending the properties to a table.
My plan:
Upvotes: 1
Views: 1728
Reputation: 7219
If I understand your question correctly, you wish to convert a JSON array into a Javascript object, since altering JSON property values to keys wouldn't be valid JSON.
To convert JSON array into Javascript object, in pure Javascript you do:
JSON.parse(yourJSONgoeshere);
Docs and examples here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
Hope it helps.
Upvotes: 4