Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NodeJS JSON array to Json obj

Posted on 2015-01-08
3
Medium Priority
?
318 Views
Last Modified: 2015-01-09
I am a NodeJS Javascript newbie

Using nodeJS  I have this JSON array that i read in as a recordset from a database.

[{"CaseType":"110","ServiceType":"12","Description":"Traffic Ticket","Reimbursment":60,"CTCategory":"SCF"}]

I need it to be a JSON object
{"CaseType":"110","ServiceType":"12","Description":"Traffic Ticket","Reimbursment":60,"Category":"TFT"}

So I can do this

var obj = JSON.parse(s);

console.log(obj.CaseType);
console.log(obj.Description);
....
console.log(obj.Category);
0
Comment
Question by:Charles Baldo
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 40539533
You can parse an array and then just access as obj[0].CaseType for the first element and so on
0
 
LVL 43

Expert Comment

by:Rob
ID: 40539597
example:

var rtn = "[{\"CaseType\":\"110\",\"ServiceType\":\"12\",\"Description\":\"Traffic Ticket\",\"Reimbursment\":60,\"CTCategory\":\"SCF\"}]";

var obj = JSON.parse(rtn);

console.dir(obj);

Open in new window


outputs

[[object Object] {
  CaseType: "110",
  CTCategory: "SCF",
  Description: "Traffic Ticket",
  Reimbursment: 60,
  ServiceType: "12"
}]

Open in new window

0
 

Author Closing Comment

by:Charles Baldo
ID: 40540138
Thanks Rob,
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question