Solved

NodeJS JSON array to Json obj

Posted on 2015-01-08
3
285 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:charlesbaldo
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
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
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:charlesbaldo
ID: 40540138
Thanks Rob,
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html Uncheck Checkbox 2 25
jQuery on Submit 4 42
Responsive Font Size 6 29
Non-Resizable Pharagraph 2 7
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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)

837 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