Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

NodeJS JSON array to Json obj

Posted on 2015-01-08
3
Medium Priority
?
307 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
[X]
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
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

688 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