how to show json data in jquery datatable - java

This is my jquery datatable ajax request... in success im getting the json data but in datatable its not showing ..its showing only loading..
<script type="text/javascript">
function inituserdatatable() {
alert("in");
try {
$('#userdetailDatatable').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "ps/getUserDetails",
"type": "post",
"datatype": "json",
"success": function(data) {
},
},
"columns": [{
'data': 'name'
},
{
'data': 'email_id'
},
{
'data': 'user_name'
},
{
'data': 'password'
}
],
dom: 'Bfrtip',
});
} catch (exp) {
alert(exp);
}
}
</script>
This is my json data from postgresql
{
"data": [{
"id": 12,
"name": "",
"email_id": "",
"user_name": "",
"password": ""
}, {
"id": 13,
"name": "Ss",
"email_id": "sd",
"user_name": "g",
"password": "g"
}]
}

Remove the following processing and serverSide options, they are not needed based on your data format.

Related

How to parse a JSON with SCIM Schemas in java

I have the following json which get from endpoint,
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:response",
"urn:scim:schemas:extension:customattrs:2.0:User"
],
"meta": {
"resourceType": "User",
"created": "2011-08-01T18:29:49.793Z",
"lastModified": "2011-08-01T18:29:49.793Z",
"version": "W/\"f250dd84f0671c3\""
},
"userName": "bjensen",
"phoneNumbers": [
{
"value": "555-555-8377",
"type": "work"
}
],
"emails": [
{
"value": "bjensen#example.com",
"type": "work",
"primary": true
}
],
"urn:scim:schemas:extension:customattrs:2.0:User": {
"userName": "bjensen",
"address": ""
}
}
please suggest me to parse the json along with schemas "urn:scim:schemas:extension:customattrs:2.0:User" into java object

Getting all elements from JSON API response

Getting an API response as below and wanted to get the names for all the fields using restassured.
{
"expand": "projects",
"projects": [
{
"expand": "issuetypes",
"issuetypes": [
{
"subtask": false,
"expand": "fields",
"fields": {
"summary": {
"required": true,
"schema": {
"type": "string",
"system": "summary"
},
"name": "Summary",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"customfield_10100": {
"required": false,
"schema": {
"type": "any",
"custom": "com.pyxis.greenhopper.jira:gh-epic-link",
"customId": 10100
},
"name": "Epic Link",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"customfield_10102": {
"required": true,
"schema": {
"type": "string",
"custom": "com.pyxis.greenhopper.jira:gh-epic-label",
"customId": 10102
},
"name": "Epic Name",
"hasDefaultValue": false,
"operations": [
"set"
]
},
}
}
]
}
]
}
I tried to get the names using respStg1.jsonPath().getList("projects.issuetypes.fields.[*].name"), but getting gpath error. Please help if there is any way to get the name of all the fields under projects.issuetypes.fields.
Try with this = [*].[*].[*].[*].name
This should work
For future you can use this link to evaluate jsonPath : http://jsonpath.com/
and for jsonPath syntax and wildcards refer this link : https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html

extract specific text (password strings) from a large JSON file in java without using the JSON helper classes

I have the following large JSON I receive from a specific REST call. I want to only extract the password strings (highlighted in bold). So I need the values.
ConfigPWD_USER.password, ConfigPWD_ROOT.password, instanceOwnerPassword, databaseUserPassword, fencedUserPassword in java. Guess I will have to search using string regex. Can someone help?
{
"deployment_name": "name1",
"model": {
"model": {
"description": "",
"nodes": [{
"id": "OS Node",
"ptype": "image:OS Node",
"attributes": {
<more json key value pairs>
**"ConfigPWD_USER.password": "<xor>NzozMzA=",
"ConfigPWD_ROOT.password": "<xor>NzozMzA="**
},
"type": "image:OS,
"groups": {},
"locked": []
}, {
"id": "disk for db instance",
"attributes": {
<more json key value pairs>
},
"type": "add disk:1.0.0",
"groups": {},
"locked": []
}, {
"id": "disk for database data",
"attributes": {
<more json key value pair>
},
"type": "disk:1.0.0",
"groups": {},
"locked": []
}, {
"id": "DB Server",
"startsAfter": ["disk for db instance",
"OS Node"
],
"locked": ["instanceMountPoint", "instanceMountPoint", "instanceMountPoint"],
"attributes": {
"instanceMountPoint": "${disk for db instance.MOUNT_POINT}",
<more json key value pair>
**"instanceOwnerPassword": "<xor>NzozMzA=",**
<more json key value pair>
**"fencedUserPassword": "<xor>NzozMzA=",**
},
"type": "DBLUN",
"groups": {}
}, {
"id": "bludbs",
"startsAfter": ["DB Server", "disk for database data"],
"locked": ["instanceName", "dataMountPoint", "instanceName", "dataMountPoint", "instanceName", "dataMountPoint"],
"attributes": {
<many json key value pairs>,
**"databaseUserPassword": "<xor>NzozMzA="**,
<many json key value pairs>
},s
"type": "sript:scrip1.exe",
"groups": {}
}],
"app_type": "application",
"name": "Default DB in Linux",
"patterntype": "vsys",
"links": [{
"id": "HostedOnLink_1",
"source": "disk for db instance",
"target": "OS Node",
"attributes": {},
"type": "HostedOnLink",
"groups": {}
},
{
"id": "HostedOnLink_2",
"source": "disk for database data",
"target": "OS Node",
"attributes": {},
"type": "HostedOnLink",
"groups": {}
}, {
"id": "HostedOnLink_3",
"source": "DB Server",
"target": "OS Node",
"attributes": {},
"type": "HostedOnLink",
"groups": {}
}, {
"id": "HostedOnLink_4",
"source": "bludb",
"target": "OS Node",
"attributes": {},
"type": "HostedOnLink",
"groups": {}
}
],
"locked": false,
"readonly": false,
"version": "1.0",
"patternversion": "1.2.3.0",
"mixinArgs": null
},
"layers": [{
"id": "layer",
"nodes": ["OS Node", "disk for db instance", "disk for database data", "DB Server", "bludb"]
}]
},
<more json key value pairs>,
"organizations": []
}
in groovy there is in-build groovy.json.JsonSlurper and code to find one of the values could be like this:
def json = new groovy.json.JsonSlurper().parseText('''
{
"deployment_name": "name1",
"model": {
"model": {
"description": "",
"nodes": [{
"id": "OS Node",
"ptype": "image:OS Node",
"attributes": {
"ConfigPWD_USER.password": "1<xor>NzozMzA=",
"ConfigPWD_ROOT.password": "1<xor>NzozMzA="
},
"type": "image:OS",
"groups": {},
"locked": []
}, {
"id": "disk for db instance",
"attributes": {
"ConfigPWD_USER.password": "2<xor>NzozMzA=",
"ConfigPWD_ROOT.password": "2<xor>NzozMzA="
},
"type": "add disk:1.0.0",
"groups": {},
"locked": []
}]
}
}
}
''')
json.model.model.nodes.collect{n-> n.attributes."ConfigPWD_USER.password" }

How to map a JSON into POJO for rest Template in java?

I have a JSON response coming from Hubspot API as following, I am having trouble to parse it into Java POJO for using with RestTemplate.
Since the Json reponse is not in form of json arrays,I am not able to create proper java classes.
Can someone please help?
The JSON response received is as following:
{
"1": {
"vid": 1,
"canonical-vid": 1,
"portal-id": 5017510,
"is-contact": true,
"profile-token": "AO_T-mOzMc0AQx3P50QBw3qJ09A30BWfeQu89iOhW5ADWb6-uIT7m37lYwSTk7ObLEYwwnpxGNM1x9rkivaT-abeu6MegOWO31EUpZ3b56hfFti61ewcGQvC-XocjM2fekCOtK5oyM1C",
"profile-url": "https://app.hubspot.com/contacts/5017510/lists/public/contact/_AO_T-mOzMc0AQx3P50QBw3qJ09A30BWfeQu89iOhW5ADWb6-uIT7m37lYwSTk7ObLEYwwnpxGNM1x9rkivaT-abeu6MegOWO31EUpZ3b56hfFti61ewcGQvC-XocjM2fekCOtK5oyM1C/",
"properties": {
"firstname": {
"value": "Cool"
},
"city": {
"value": "Cambridge"
},
"createdate": {
"value": "1539332326199"
},
"company": {
"value": "HubSpot"
},
"state": {
"value": "MA"
},
"email": {
"value": "coolrobot#hubspot.com"
},
"website": {
"value": "http://www.HubSpot.com"
},
"jobtitle": {
"value": "Robot"
},
"lastmodifieddate": {
"value": "1539332330206"
},
"lastname": {
"value": "Robot (Sample Contact)"
}
}
},
"51": {
"vid": 51,
"canonical-vid": 51,
"portal-id": 5017510,
"is-contact": true,
"profile-token": "AO_T-mNsLUnhG0QdyfV6D_JZhoqldgC_jYOZswkSrsgRW1uvUZpajXSjd-83OtQEdptpio0VAgtGD3_qIOe_4vnijJ8_q6traOskjw5A48d1RhghdFuqiDpgz7pRcuzTrMjsvWF5Oat3",
"profile-url": "https://app.hubspot.com/contacts/5017510/lists/public/contact/_AO_T-mNsLUnhG0QdyfV6D_JZhoqldgC_jYOZswkSrsgRW1uvUZpajXSjd-83OtQEdptpio0VAgtGD3_qIOe_4vnijJ8_q6traOskjw5A48d1RhghdFuqiDpgz7pRcuzTrMjsvWF5Oat3/",
"properties": {
"firstname": {
"value": "Brian"
},
"city": {
"value": "Cambridge"
},
"createdate": {
"value": "1539332326434"
},
"company": {
"value": "HubSpot"
},
"state": {
"value": "MA"
},
"email": {
"value": "bh#hubspot.com"
},
"website": {
"value": "http://www.HubSpot.com"
},
"jobtitle": {
"value": "CEO"
},
"lastmodifieddate": {
"value": "1539332334158"
},
"lastname": {
"value": "Halligan (Sample Contact)"
}
}
}
}
See this link, http://www.jsonschema2pojo.org/ in it you pass the JSON and it mounts the POJO for you, however you want.
I tested with your JSON and generated perfectly.
you can use Jackson to convert JSON response into POJO class.
Sample code:
ObjectMapper mapper = new ObjectMapper();
POJOClass pojoclassObj = mapper.readValue(jsonResponse, POJOClass.class);

Pojo/Entity corresponding to json response from Azure REST API

I have written a java class which hits the Azure REST API's and gets me the json response. for example below-
{
"value": [
{
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "Storage",
"id": "/subscriptions/cc60365e-3193-xxxx-b0f6-xxxxxxx/resourceGroups/WebServer-ubuntu/providers/Microsoft.Storage/storageAccounts/webserverubuntudiagxxx",
"name": "webserverubuntudiag4xx",
"type": "Microsoft.Storage/storageAccounts",
"location": "eastus",
"tags": {},
"properties": {
"networkAcls": {
"bypass": "AzureServices",
"virtualNetworkRules": [],
"ipRules": [],
"defaultAction": "Allow"
},
"trustedDirectories": [
"50228742-xxx-4cd2-xxx-3e50b7a62xx1"
],
"supportsHttpsTrafficOnly": false,
"encryption": {
"services": {
"file": {
"enabled": true,
"lastEnabledTime": "2018-03-26T15:02:26.8078850Z"
},
"blob": {
"enabled": true,
"lastEnabledTime": "2018-03-26T15:02:26.8078850Z"
}
},
"keySource": "Microsoft.Storage"
},
"provisioningState": "Succeeded",
"creationTime": "2018-03-26T15:02:26.6359768Z",
"primaryEndpoints": {
"blob": "https://webserverubuntudiagxx.blob.core.windows.net/",
"queue": "https://webserverubuntudiag4xx.queue.core.windows.net/",
"table": "https://webserverubuntudiagxx.table.core.windows.net/",
"file": "https://webserverubuntudiag4xx.file.core.windows.net/"
},
"primaryLocation": "eastus",
"statusOfPrimary": "available"
}
}
]
}
My questions is: Are there any model/pojo/bean already available to map this json to java object ?
I need to map the data from above json into the java beans/pojos to display into jsp pages, do I need to separately create custom pojos or there are any already in Azure libraries/sdk ? any suggestions?

Categories