Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Can someone please show me how I can get my JSON data and use it in javascript?

My data looks like this...

[{
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 501",
    "2": "Parameter 501",
    "setting_value": "true",
    "3": "true"
}, {
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 502",
    "2": "Parameter 502",
    "setting_value": "true",
    "3": "true"
}, {
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 503",
    "2": "Parameter 503",
    "setting_value": "false",
    "3": "false"
}, {
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 504",
    "2": "Parameter 504",
    "setting_value": "6",
    "3": "6"
}, {
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 505",
    "2": "Parameter 505",
    "setting_value": "16",
    "3": "16"
}, {
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 506",
    "2": "Parameter 506",
    "setting_value": "17",
    "3": "17"
}, {
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 507",
    "2": "Parameter 507",
    "setting_value": "3",
    "3": "3"
}, {
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 508",
    "2": "Parameter 508",
    "setting_value": "19",
    "3": "19"
}, {
    "id": "1",
    "0": "1",
    "filename": "CONFIG 1",
    "1": "CONFIG 1",
    "setting_name": "Parameter 509",
    "2": "Parameter 509",
    "setting_value": "19",
    "3": "19"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 502",
    "2": "Parameter 502",
    "setting_value": "false",
    "3": "false"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 503",
    "2": "Parameter 503",
    "setting_value": "true",
    "3": "true"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 504",
    "2": "Parameter 504",
    "setting_value": "6",
    "3": "6"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 505",
    "2": "Parameter 505",
    "setting_value": "16",
    "3": "16"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 506",
    "2": "Parameter 506",
    "setting_value": "17",
    "3": "17"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 507",
    "2": "Parameter 507",
    "setting_value": "3",
    "3": "3"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 508",
    "2": "Parameter 508",
    "setting_value": "18",
    "3": "18"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 509",
    "2": "Parameter 509",
    "setting_value": "19",
    "3": "19"
}, {
    "id": "2",
    "0": "2",
    "filename": "CONFIG 2",
    "1": "CONFIG 2",
    "setting_name": "Parameter 501",
    "2": "Parameter 501",
    "setting_value": "false",
    "3": "false"
}, false]

Basically I have four fields... id, filename, setting_name and setting_value.

I need to know how I can get this and convert it into a javascript array, so that I may use it withing my logic. N

share|improve this question
possible duplicate of How to parse JSON data, using javascript – vol7ron Aug 26 '11 at 1:13
@vol7ron Looks like an accidental double-post. This one came first – Phil Aug 26 '11 at 1:15
1  
@Phil: I just like to close them both, for the sheer fact that it's a double and the question is horrible to look at. – vol7ron Aug 26 '11 at 1:17
1  
@Carl Weis, please spend more time on your questions. – zzzzBov Aug 26 '11 at 1:19
1  
I went ahead and at least beautified it – vol7ron Aug 26 '11 at 1:21
show 2 more comments

2 Answers

up vote 3 down vote accepted
o = JSON.parse('your string here');
console.log(o);

http://jsfiddle.net/Lenuk/

share|improve this answer

Your syntax for JSON data is incorrect. Json data is enclosed within {} and not []. Still for parsing JSON data use json2.js library from the link.

https://github.com/douglascrockford/JSON-js/blob/master/json2.js

and use;

var myObject = JSON.parse(myJSONtext, reviver);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.