NodeJS JSON array to Json obj

Posted on 2015-01-08
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);

Question by:Charles Baldo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 43

Accepted Solution

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

Expert Comment

ID: 40539597

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

var obj = JSON.parse(rtn);


Open in new window


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

Open in new window


Author Closing Comment

by:Charles Baldo
ID: 40540138
Thanks Rob,

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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…

710 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