angularJS JSON parsing - json

I am new to angularJS and trying to parse the data and display it on a page.
{
"count": 13,
"status": 200,
"statusMessage": "OK",
"userContact": [
{
"user": {
"id": 1,
"firstName": "test",
"lastName": "test",
"universityId": 1,
"email": "test#harbingergroup.com",
"password": "",
"phoneNo": "1234567890",
"gender": "M",
"userType": 1,
"medicalComments": "",
"dob": "2015-02-22",
"universityAffiliation": 1,
"cityId": "1"
},
"userContactList": {
"count": 2,
"status": 200,
"statusMessage": "OK",
"contact": [
{
"id": 2,
"userId": 1,
"firstName": "test",
"lastName": "user",
"phoneNo": "9876543210",
"email": "test#example.com"
},
{
"id": 24,
"userId": 1,
"firstName": "first1",
"lastName": "last1",
"phoneNo": "9876543210",
"email": "test#example.com"
}
]
}
}]
}
this is my JSON data.What i am trying is :
<tr ng-repeat="studentDetails in studentProfileData">
studentDetails.status for getting status and studentDetails.userContacts.firstName for first name
but I am not getting the data. What is wrong here?

Assuming that studentProfileData contains a list of users (userContact):
studentDetails.user.firstName
will contain "test"

Related

Accessing the Data in json object

This Works
app.get('/api/v1/admin/getAllUsers',async function (req,res,next){
try {
if (!req.headers.authorization || !req.headers.authorization.startsWith('Bearer ') || !req.headers.authorization.split(' ')[1]) {
return res.status(422).json({ message: 'Please Provide Token!' })
}
dbConn.query('select * from fasta_users; select * from fasta_admin_users;select Name, email,password,phone,role,status,created_at from fasta_riders;', function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results , message: 'users list' });
});
} catch (err) {
next(err);
}
})
It returns the data i want without problems but the Json is Looking like this
{
"error": false,
"data": [
[
{
"id": 1,
"fastaUserId": "",
"fullname": "John Qasim",
"email": "j_qasim001#aol.com",
"password": "$2a$12$iAzLsIEcOJpDSSgdUmJBR.e8pWdieUg7N4bFiW0lkgBsQQDA6DwPG",
"state": "Imo",
"role": "Customers",
"city": "Owerri",
"phone_num": "08076631261",
"created_at": "2022-05-17T14:58:26.000Z"
},
{
"id": 2,
"fastaUserId": "FU-71198",
"fullname": "z",
"email": "z#gmail.com",
"password": "$2a$12$a9ibquFv477e6KL3N49JweVoiSmDXR0UVcM5xCkB39/8loKZ/u0bq",
"state": "z",
"role": "z",
"city": "user",
"phone_num": "z",
"created_at": "2022-05-17T17:57:39.000Z"
}
],
[
{
"id": 1,
"fastaUserId": "",
"fullname": "John Legend",
"email": "john.legend#gmail.com",
"password": "$2a$12$KrW0YKsJmvlp2z5uF4V10uLIjcPpSl1ba/LiWuiRpaLs/XRmguXDy",
"phone_num": "0188272610",
"avatar": "test_pic",
"role": "Administrator",
"status": "Active",
"created_at": "2022-05-11T17:48:39.000Z"
},
{
"id": 2,
"fastaUserId": "FA-76249",
"fullname": "James Hall",
"email": "jameshallblog.com#gmail.com",
"password": "$2a$12$j711FBY441CHwacisjcL9OT9Rjb5Yll8VzdSncKJilC0Pku9i2RP2",
"phone_num": "090865735422",
"avatar": "https://oxfordssocustomerapi.azurewebsites.net/Docs/Users/OIG-00424.jpg",
"role": "Administrator",
"status": "Active",
"created_at": "2022-05-17T17:51:03.000Z"
}
],
[
{
"Name": "Karen Mitchelle",
"email": "k.m.boon#gmail.com",
"password": "$2a$12$PCTK8okWO/ApoNSgXXTIl.oxzwqf.zlHHJaEvxtfxpUrnI1IaGNQC",
"phone": "08128829102",
"role": "Rider",
"status": "Active",
"created_at": "2022-05-17T14:59:22.000Z"
}
]
],
"message": "users list"
}
But I do not want this ^^^ above as a Response. I want something like this instead.
"data":[{
"id": 1,
"fastaUserId": "",
"fullname": "John Qasim",
"email": "j_qasim001#aol.com",
"password": "$2a$12$iAzLsIEcOJpDSSgdUmJBR.e8pWdieUg7N4bFiW0lkgBsQQDA6DwPG",
"state": "Imo",
"role": "Customers",
"city": "Owerri",
"phone_num": "08076631261",
"created_at": "2022-05-17T15:58:26.000Z"
},
{
"id": 1,
"fastaUserId": "",
"fullname": "alex roman",
"email": "alex.roman#juno.com",
"password": "$2a$12$sXpfYaQQIwoBf1KMaPrgT.PioHY4Y6SXD1lpheDB9EPTwfRtsg1p.",
"state": "Lagos",
"city": "city",
"phone_num": "08111111111",
"company_type": "Registered",
"company_name": "Polaris Shipping Inc.",
"company_regnum": "RC-123456",
"c_license": 1,
"role": "Delivery man",
"l_licensenumber": "LAG-2372328",
"company_address": "150 Wole Madariola Close",
"num_employees": "200",
"company_nature": "Sole Propietorship",
"created_at": "2022-05-17T15:57:41.000Z"
},
{
"id": 1,
"fastaUserId": "",
"fullname": "John Legend",
"email": "john.legend#gmail.com",
"password": "$2a$12$KrW0YKsJmvlp2z5uF4V10uLIjcPpSl1ba/LiWuiRpaLs/XRmguXDy",
"phone_num": "0188272610",
"avatar": "test_pic",
"role": "Administrator",
"status": "Active",
"created_at": "2022-05-11T18:48:39.000Z"
},
{
"id": 1,
"Name": "Karen Mitchelle",
"RidersID": "FR-60842",
"Status": "Active",
"email": "k.m.boon#gmail.com",
"password": "$2a$12$PCTK8okWO/ApoNSgXXTIl.oxzwqf.zlHHJaEvxtfxpUrnI1IaGNQC",
"phone": "08128829102",
"No_deliveries": "200",
"rating": "5",
"state": "Lagos",
"city": "Lagos",
"role": "Rider",
"address": "150 Wole Kolawole Str. Lagos Nigeria",
"bike_manufacturer": "Suzuki",
"bike_model": "Suzuki 400",
"bike_year": "2012",
"engine_power": "HP8",
"bike_color": "red",
"license_number": "SMK900-LA",
"license_expiry": "2027-05-01",
"vehicle_id": "LA8373Q2",
"created_at": "2022-05-17T15:59:22.000Z"
}
]
What must i do in my code above to access that data object from results in the response here like this return res.send({ error: false, data: results , message: 'users list' }); and return something like the second Json as shown above? I am trying to get this solved and nothing i have seen on the internet is being quite helpful here. Please i need help

Fetch data from two table in nodejs from mysql in rest Api

js Developers
I am trying to create Rest api in node.js . I want to get data from two table in mysql database. First table is USERS which contain {id, name, email} and Second table is USERINFO which contain {id, mobile , address, user_id} here user_id is work as foreign key that is associate with USERS table. In USERINFO table more than one information.
First table Look like this
Second Table look like this
I got this type of output
[
{
"id": 1,
"name": "abc",
"email": "abc#xxx.com",
"mobile": "11111",
"address": "qqq",
"user_id": 1
},
{
"id": 2,
"name": "XYZ",
"email": "xyz#xxx.com",
"mobile": "22222",
"address": "wwwww",
"user_id": 2
},
{
"id": 3,
"name": "abc",
"email": "abc#xxx.com",
"mobile": "3333333",
"address": "ssssss",
"user_id": 1
},
{
"id": 4,
"name": "XYZ",
"email": "xyz#xxx.com",
"mobile": "444444",
"address": "nnnnn",
"user_id": 2
}]
But i want this type output
[
{
"id": 1,
"name": "abc",
"email": "abc#xxx.com",
"info": [
{
"mobile": "11111",
"address": "qqq",
},
{
"mobile": "3333333",
"address": "ssssss",
}
],
"user_id": 1
},
{
"id": 2,
"name": "XYZ",
"email": "xyz#xxx.com",
"info": [
{
"mobile": "22222",
"address": "wwwww",
},
{
"mobile": "444444",
"address": "nnnnn",
}
],
"user_id": 2
}]
Thanks in Advance

How to concat string to an existing array element using lodash

I have a json object which has the following form
"data": [{
"firstName": "XYZ",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo"
}, {
"firstName": "ABC",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo1"
}, {
"firstName": "EFG",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo2"
}]
I want the following output to concat the logo name with its path using lodash in nodejs
"data": [{
"firstName": "XYZ",
"lastName": "Admin",
"userId": 1,
"companyLogo":"E:/Logo"
}, {
"firstName": "ABC",
"lastName": "Admin",
"userId": 1,
"companyLogo":"E:/Logo1"
}, {
"firstName": "EFG",
"lastName": "Admin",
"userId": 1,
"companyLogo":"E:/Logo2"
}]
Is there any function existing which supports this type of concatenation?
There's no need for an external library:
var data = [
{
"firstName": "XYZ",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo"
},
{
"firstName": "ABC",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo1"
},
{
"firstName": "EFG",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo2"
}
]
var new_data = data.map(function(elem){ elem.companyLogo = "E: /" + elem.companyLogo; return elem });
console.log(new_data);

Jmeter JSON Path Assertion

Below is my JSON response data, I need to do assertion using the below response. I tried in many ways to write JSON path & Expected Value. Always assertion fails. What I want is please help to write the path and expected value for the below data
{
"statusCode": 200,
"statusMessage": "Success",
"errorMessage": "",
"responseData": {
"id": 15,
"userName": "partner#tarento.com",
"firstName": "tarento",
"lastName": "test1",
"phoneNumber": "1234567812",
"email": "partner#tarento.com",
"password": "",
"city": "",
"agentList": [
{
"id": 37,
"userName": "Rahul.antonyRaj#tarento.com",
"firstName": "Sanjay",
"lastName": "rahul",
"phoneNumber": "7411269480",
"email": "Rahul.antonyRaj#tarento.com",
"password": "",
"active": true
},
{
"id": 68,
"userName": "jinesh.sumedhan#tareto.com",
"firstName": "jinesh",
"lastName": "sumedhan",
"phoneNumber": "9400993826",
"email": "jinesh.sumedhan#tareto.com",
"password": "",
"active": true
},
{
"id": 108,
"userName": "a.sanjayrahul#gmail.com",
"firstName": "Rahul",
"lastName": "Antony",
"phoneNumber": "9994590241",
"email": "a.sanjayrahul#gmail.com",
"password": "",
"active": true
},
{
"id": 304,
"userName": "a.sanjayrajish#gmail.com",
"firstName": "Agent",
"lastName": "Agent",
"phoneNumber": "9025699716",
"email": "a.sanjayrajish#gmail.com",
"password": "",
"active": true
}
],
"roleName": "admin",
"sessionKey": "435tnerLt9813942160478oDse46345635#1",
"partner": {
"id": 1,
"name": "Tarento",
"cityList": [
"bangalore",
"mumbai"
],
"phone": "1234567812",
"url": ""
},
"isActive": true,
"isDeleted": false,
"roleId": 1,
"countryCode": "",
"tags": [
{
"tagId": 1,
"name": "all",
"description": "this is default tag of all driver."
},
{
"tagId": 2,
"name": "airport",
"description": ""
},
{
"tagId": 3,
"name": "street",
"description": "any text message"
},
{
"tagId": 255,
"name": "night",
"description": "night"
}
]
}
}
I received the following response
For start following JSONPath Assertion will test your statusCode
$.statusCode
put 200 to Expected Value of JSONPath Assertion.
This one is for userName
$.responseData.userName
Easy, isn't it? See Parsing JSON guide for more useful examples and how-tos.
I found the JSR223 Assertion with script language javascript to be the easiest. at least if you have knowledge in java and javascript. And no need to add any plugins.
My working code in detail:
var json = JSON.parse(SampleResult.getResponseDataAsString());
if (json.statusCode != 200) {
AssertionResult.setFailureMessage(""
+ json.statusCode
+ " " + json.statusMessage
+ " " + json.errorMessage);
AssertionResult.setFailure(true);
}
I personally prefer to use BSF PostProcessor in coupling with Groovy language. Example of how to parse JSON with Groovy you can find here how to parse json using groovy

ACS review condition failure

I'm working in an android app using Titanium appcelerator.
Now i'm trying out ACS REVIEWS .. I'm getting the whole db result , i need to filter by id. For that i tried to put Where condition ..But it doesn't working..
My Json
{
"id": "52ea3eba08a3e5704b330c2a2a",
"rating": 3,
"created_at": "2014-01-30T11:59:54+0000",
"updated_at": "2014-01-30T11:59:54+0000",
"user": {
"id": "52e5f3881356b440b4b09c805",
"created_at": "2014-01-27T05:50:00+0000",
"updated_at": "2014-01-29T04:29:49+0000",
"external_accounts": [
],
"confirmed_at": "2014-01-27T05:50:00+0000",
"username": "Gk",
"role": "j",
"admin": "false",
"custom_fields": {
"phone": "91959454651",
"usertype": "0",
"status": "1",
"ios_deviceid": "",
"country_code": "IN",
"verify_code": "4574",
"verified": "1",
"contact_sms": "1",
"contact_message": "1",
"contact_email": "1",
"contact_phone": "0",
"android_gcmid": "APA91bE0mcScNlXbCENZ2D_9jylgwdwOJ6vYTqnI_Kzqx2lqLWblnn6mT4PJ6iZRNxUGA66Ke7RJ0CKC44DL3mturNs_w3QT7KhTVIWbQE2tJgBHU7gpzB2GG4sFGXL6LiayJ5zEn_AGhxBlw"
}
},
"reviewed_object": {
"type": "Post",
"id": "52e7800313556440b4b0aa134"
},
"custom_fields": {
}
},
{
"id": "52ea3e9d4430d0b1e0c1c16",
"rating": 3,
"created_at": "2014-01-30T11:59:25+0000",
"updated_at": "2014-01-30T11:59:25+0000",
"user": {
"id": "52e8fe464643d0b130b85f5",
"first_name": "Ganesh",
"last_name": "test",
"created_at": "2014-01-29T13:12:38+0000",
"updated_at": "2014-01-29T13:12:38+0000",
"external_accounts": [
],
"confirmed_at": "2014-01-29T13:12:38+0000",
"username": "john",
"role": "r",
"admin": "false"
},
"reviewed_object": {
"type": "Post",
"id": "52e7800343556b4dsfsdfh3434"
},
"custom_fields": {
}
},
]
I want to filter using this id..
"reviewed_object": {
"type": "Post",
"id": "52e7800343556b4dsfsdfh3434"
}
What should i write in my WHERE Condition..
Cloud.Reviews.query({
page : 1,
per_page : 20,
where : {
rating : {
'$gt' : 1.0
},
},
order : "-created_at"
}
i have added my post id condition without where statement ..It worked perfectly..
My Code:
Cloud.Reviews.query({
page :1,
per_page : 20,
post_id : Your Post id
}, function(e) {
if (e.success) {