Related
Currently building an API with Strapi with the model of a blog post such that each Post has a Title, Slug, Content, and user Relation.
What data looks like:
{
"data": [
{
"id": 1,
"attributes": {
"title": "Test1",
"createdAt": "2022-07-24T18:33:34.195Z",
"updatedAt": "2022-07-24T18:33:34.863Z",
"publishedAt": "2022-07-24T18:33:34.861Z",
"user": {
"data": {
"id": 1,
"attributes": {
"username": "xyz",
"email": "xyz#gmail.com",
"provider": "local",
"confirmed": false,
"blocked": false,
"createdAt": "2022-07-24T14:28:16.466Z",
"updatedAt": "2022-07-24T14:29:00.126Z"
}
}
}
}
}
],
}
What I want it to look like:
{
{
"id": 1,
"title": "Test1",
"createdAt": "2022-07-24T18:33:34.195Z",
"updatedAt": "2022-07-24T18:33:34.863Z",
"publishedAt": "2022-07-24T18:33:34.861Z",
"user": {
"id": 1,
"username": "xyz",
"email": "xyz#gmail.com",
"provider": "local",
"confirmed": false,
"blocked": false,
"createdAt": "2022-07-24T14:28:16.466Z",
"updatedAt": "2022-07-24T14:29:00.126Z"
}
}
}
By default, the data is wrapped in unnecessarily tiresome arrays and objects and any attempt to edit the scehma.json causes the API to crash.
How can I fix this?
you can try this solution :
const x = {
"data": [
{
"id": 1,
"attributes": {
"title": "Test1",
"createdAt": "2022-07-24T18:33:34.195Z",
"updatedAt": "2022-07-24T18:33:34.863Z",
"publishedAt": "2022-07-24T18:33:34.861Z",
"user": {
"data": {
"id": 1,
"attributes": {
"username": "xyz",
"email": "xyz#gmail.com",
"provider": "local",
"confirmed": false,
"blocked": false,
"createdAt": "2022-07-24T14:28:16.466Z",
"updatedAt": "2022-07-24T14:29:00.126Z"
}
}
}
}
}
],
}
const data = x.data[0]
const users = {id: data.attributes.user.data.id , ...data.attributes.user.data.attributes}
const result = {id: data.id , title: data.attributes.title , createdAt: data.attributes.createdAt , updatedAt: data.attributes.updatedAt , publishedAt: data.attributes.publishedAt , user: users }
```
In a react component I am storing data in the localStorage using a network call in this way:
React.useEffect(() => {
setIsLoading(true);
getCategoryList().then((category) => {
setCategories(category.data.data.map((result: any) => ({ ...result })));
localStorage.setItem("categories", JSON.stringify(category));
});
setIsLoading(false);
}, []);
console.log({ categories });
I am retrieving this data from localStorage in another component in this way:
const categories = JSON.parse(localStorage.getItem("categories") || "{}");
console.log(categories);
From the localStorage the data structure is:
{
"data": {
"message": "fetched categories successfully",
"success": true,
"data": [
{
"name": "diagnostic",
"slug": "hospital",
"description": "diagnostic center",
"status": "active",
"created_by": "tripping_card",
"updated_by": "nabila",
"created_at": "2021-04-06T12:07:18.195Z",
"updated_at": "2021-04-15T10:47:01.04Z"
},
{
"name": "Private Chamber",
"slug": "private-chamber",
"description": "Private Chamber as care provider",
"status": "active",
"created_by": "tripping_card",
"updated_by": "tripping_card",
"created_at": "2021-04-06T16:46:27.313Z",
"updated_at": "2021-04-06T16:46:27.313Z"
},
{
"name": "Diagnostic Center",
"slug": "diagnostic-center",
"description": "Diagnostic Center as care provider",
"status": "active",
"created_by": "01400000000",
"updated_by": "01400000000",
"created_at": "2021-04-08T13:46:39.684Z",
"updated_at": "2021-04-08T13:46:39.684Z"
},
{
"name": "Blood Bank",
"slug": "fgf",
"description": "Shondhani Blood Bank service provider",
"status": "active",
"created_by": "ishak",
"updated_by": "ishak",
"created_at": "2021-04-12T11:31:56.525Z",
"updated_at": "2021-04-13T09:06:38.508Z"
},
{
"name": "Organ Center",
"slug": "center",
"description": "Center for Organ donation",
"status": "inactive",
"created_by": "ishak",
"updated_by": "ishak",
"created_at": "2021-04-12T11:33:57.136Z",
"updated_at": "2021-04-13T11:35:04.468Z"
},
{
"name": "Health Card",
"slug": "provide",
"description": "Center to Provide health card",
"status": "active",
"created_by": "ishak",
"updated_by": "ishak",
"created_at": "2021-04-12T11:50:49.064Z",
"updated_at": "2021-04-13T09:08:10.101Z"
},
{
"name": "Patient Sample Collection",
"slug": "sample",
"description": "Collect Blood and other samples",
"status": "inactive",
"created_by": "ishak",
"updated_by": "ishak",
"created_at": "2021-04-12T11:51:47.529Z",
"updated_at": "2021-04-13T11:37:28.52Z"
},
{
"name": "Clinic",
"slug": "clinic",
"description": "Green Delta Clinic",
"status": "active",
"created_by": "ishak",
"updated_by": "ishak",
"created_at": "2021-04-12T12:01:22.077Z",
"updated_at": "2021-04-18T05:39:19.967Z"
},
{
"name": "DGHS",
"slug": "dghs",
"description": "Govt Hospital",
"status": "inactive",
"created_by": "ishak",
"updated_by": "ishak",
"created_at": "2021-04-14T06:23:14.172Z",
"updated_at": "2021-04-14T06:41:01.175Z"
},
{
"name": "Hospital",
"slug": "hospital",
"description": "Hospital as primary provider",
"status": "active",
"created_by": "nabila",
"updated_by": "nabila",
"created_at": "2021-04-15T17:31:21.105Z",
"updated_at": "2021-04-15T17:31:21.105Z"
}
]
},
"status": 200,
"statusText": "OK",
"headers": {
"content-length": "676",
"content-type": "application/json"
},
"config": {
"url": "https://api-dev.evaly.com.bd/ehealth-provider/api/v1/admin/category",
"method": "get",
"headers": {
"Accept": "application/json, text/plain, */*",
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImlzaGFrIiwiZ3JvdXBzIjpbIlZvdWNoZXJWaWV3ZXIiLCJOb3RlRW50cnkiLCJDaGF0TWFuYWdlciIsIk5vdGVNYW5hZ2VyIiwiZWJhemFyTWFuYWdlciIsIkJ1bGtBZG1pbiIsIk9yZGVyTWFuYWdlciIsIkNhbXBhaWduTWFuYWdlciIsIkNhbXBhaWduQWRtaW4iLCJCcmFuZE1hbmFnZXIiLCJQcm9kdWN0TWFuYWdlciIsIkNoYXRBZG1pbiIsIkVmb29kTWFuYWdlciIsIkFjY291bnRzQWRtaW4iLCJTaG9wT3duZXIiLCJCYWxhbmNlTWFuYWdlciIsIkVmb29kQ3VzdG9tZXJTZXJ2aWNlIiwiRWZvb2RBZG1pbiIsIkRhdGFFeHBvcnRlciIsIkFwcG9pbnRtZW50QWRtaW4iLCJDYXRlZ29yeU1hbmFnZXIiLCJFa2hhdGFBZG1pbiIsIkVmb29kQ29udGVudE1hbmFnZXIiLCJFdmFseUVtcGxveWVlIiwiVGVjaFN1cHBvcnQiLCJTaG9wTWFuYWdlciIsIkNhc2hiYWNrQWRtaW4iLCJlYmF6YXJBZG1pbiIsIklzc3VlUmVzb2x1dGlvbk1hbmFnZXIiLCJPcmRlclN0YXR1c1VwZGF0ZSIsIlByb2R1Y3RBZG1pbiIsIkhlcm9NYW5hZ2VyIiwiVm91Y2hlckFkbWluIiwiRWZvb2RDb250ZW50QWRtaW4iLCJJc3N1ZVJlc29sdXRpb25BZG1pbiIsIlZvdWNoZXJNYW5hZ2VyIiwiTm90aWZpY2F0aW9uTWFuYWdlciIsIk9yZGVyQ2FuY2VsIiwiQ29tcGFueUFkbWluIiwiRWpvYnNFdmFseUFkbWluIiwiQnVsa1Blcm1pc3Npb24iLCJTaG9wQWRtaW4iLCJPcmRlckFkbWluIiwiVGVjaEFkbWluIiwiQ29tcGFueU1hbmFnZXIiLCJBY2NvdW50c01hbmFnZXIiLCJSZWZ1bmRNYW5hZ2VyIiwiSFJNYW5hZ2VyIiwiRW1wbG95ZWVNYW5hZ2VyIiwiQXNzZXRNYW5hZ2VyIiwiSFJBZG1pbiIsIkhlcm9BZG1pbiJdLCJmaXJzdF9uYW1lIjoiSXNoYWsiLCJsYXN0X25hbWUiOiJBaGFtbWVkIiwiaXNfc3RhZmYiOnRydWUsImlzX2FjdGl2ZSI6dHJ1ZSwiaXNfc3VwZXJ1c2VyIjp0cnVlLCJ2ZXJpZmllZCI6dHJ1ZSwidXNlcl90eXBlIjoiZW1wbG95ZWUiLCJ1c2VyX3N0YXR1cyI6ImFjdGl2ZSIsImVtYWlsIjoic29tZUBlbWFpbC5uZXQiLCJjb250YWN0IjoiMDEzMjQ4MjM0Li4iLCJkYXRlX2pvaW5lZCI6IjIwMTktMDgtMjlUMTI6MTA6MzhaIiwidG9rZW5fdHlwZSI6ImFjY2VzcyIsImlzX2VhdXRoIjp0cnVlLCJleHAiOjE2MTg3ODU1NzV9.PhRCPslJyjYj7PqKVgKzfEFi8gE6mnmsO1alcCj791Y"
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1
},
"request": {}
}
Now I am mapping this data like this:
{categories &&
categories.data.data.map(
({ category }: { category: any }, { index }: { index: any }) => (
<div key={index}>
{category && category.length > 0
? category.slug
: "No data"}
</div>
)
)}
But its not printing the slugs rather its printing No Data 10 times. I am not sure whats wrong with the code block.
Try the below if categories is a state (This is because you seem to have remapped from that data-structure to just having categories array as your state inside the useEffect) :-
{categories.map(
(category:any, index:any ) => (
<div key={index}>
{category.slug}
</div>
)
)}
Note :- Here I have assumed that categories state default value is [] i.e. an empty array.
Also in case you're directly picking stuff from localStorage and then trying to render it, the mapping should be like so :-
{categories &&
categories.data.data.map(
(category:any, index : any) => (
<div key={index}>
{category.slug}
</div>
)
)}
You are calling .length on the category object. try this:
{category ? category.slug : "No data"}
I writing convenience wrapper on top of the Coinbase API.
One of the requirements is to get all user accounts.
Using proper set of scopes and after a successful OAuth authentication I can use /accountsendpoint.
But the answer is confusing:
{
"data": [
{
"id": "xxxx-xxxx-xxxx-xxxx",
"name": "BTC Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "BTC",
"name": "Bitcoin",
"color": "#F7931A",
"exponent": 8,
"type": "crypto",
"sort_index": 100,
"address_regex": "^([13][a-km-zA-HJ-NP-Z1-9]{25,34})|^(bc1([qpzry9x8gf2tvdw0s3jn54khce6mua7l]{39}|[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{59}))$"
},
"balance": {
"amount": "0.03115207",
"currency": "BTC"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "ETC",
"name": "ETC Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "ETC",
"name": "Ethereum Classic",
"color": "#59D4AF",
"exponent": 8,
"type": "crypto",
"sort_index": 103,
"address_regex": "^(?:0x)?[0-9a-fA-F]{40}$"
},
"balance": {
"amount": "0.00000000",
"currency": "ETC"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "ZRX",
"name": "ZRX Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "ZRX",
"name": "0x",
"color": "#302C2C",
"exponent": 8,
"type": "crypto",
"sort_index": 105,
"address_regex": "^(?:0x)?[0-9a-fA-F]{40}$"
},
"balance": {
"amount": "0.00000000",
"currency": "ZRX"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "BAT",
"name": "BAT Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "BAT",
"name": "Basic Attention Token",
"color": "#FF5000",
"exponent": 8,
"type": "crypto",
"sort_index": 106,
"address_regex": "^(?:0x)?[0-9a-fA-F]{40}$"
},
"balance": {
"amount": "0.00000000",
"currency": "BAT"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "USDC",
"name": "USDC Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "USDC",
"name": "USD Coin",
"color": "#2775CA",
"exponent": 6,
"type": "crypto",
"sort_index": 107,
"address_regex": "^(?:0x)?[0-9a-fA-F]{40}$"
},
"balance": {
"amount": "0.000000",
"currency": "USDC"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "ZEC",
"name": "ZEC Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "ZEC",
"name": "Zcash",
"color": "#ECB244",
"exponent": 8,
"type": "crypto",
"sort_index": 108,
"address_regex": "^(t1|t3)[a-km-zA-HJ-NP-Z1-9]{33}$"
},
"balance": {
"amount": "0.00000000",
"currency": "ZEC"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "DAI",
"name": "DAI Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "DAI",
"name": "Dai",
"color": "#FFB74D",
"exponent": 8,
"type": "crypto",
"sort_index": 115,
"address_regex": "^(?:0x)?[0-9a-fA-F]{40}$"
},
"balance": {
"amount": "0.00000000",
"currency": "DAI"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "LINK",
"name": "LINK Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "LINK",
"name": "Chainlink",
"color": "#0667D0",
"exponent": 8,
"type": "crypto",
"sort_index": 122,
"address_regex": "^(?:0x)?[0-9a-fA-F]{40}$"
},
"balance": {
"amount": "0.00000000",
"currency": "LINK"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "XRP",
"name": "XRP Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "XRP",
"name": "XRP",
"color": "#222222",
"exponent": 6,
"type": "crypto",
"sort_index": 125,
"address_regex": "^r[1-9a-km-zA-HJ-NP-Z]{25,35}$"
},
"balance": {
"amount": "0.000000",
"currency": "XRP"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "REP",
"name": "REP Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "REP",
"name": "Augur",
"color": "#553580",
"exponent": 8,
"type": "crypto",
"sort_index": 126,
"address_regex": "^(?:0x)?[0-9a-fA-F]{40}$"
},
"balance": {
"amount": "0.00000000",
"currency": "REP"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
},
{
"id": "XLM",
"name": "XLM Wallet",
"primary": true,
"type": "wallet",
"currency": {
"code": "XLM",
"name": "Stellar Lumens",
"color": "#000000",
"exponent": 7,
"type": "crypto",
"sort_index": 127,
"address_regex": "^G[A-Z2-7]{55}$"
},
"balance": {
"amount": "0.0000000",
"currency": "XLM"
},
"createdAt": null,
"updatedAt": null,
"resource": "account",
"resourcePath": null
}
]
The endpoint returns incomplete list of the user accounts. I have at least two more coinbase accounts with non zero balance.
Additionally, the id are inconsistent - for BTC we have some sort of UUID in place, while other wallets are using currency code.
This makes /transactions endpoint requests returning 404 for the requests trying to point to the different than BTC wallets:
https://api.coinbase.com/v2/accounts/EOS/transactions.
Any idea how to get full list of accounts, plus how to work with the ID for other than BTC wallets?
The scopes I am using:
("wallet:accounts:read",
"wallet:accounts:update",
"wallet:transactions:read",
"wallet:transactions:request",
"wallet:transactions:send");
I added a transaction to one of the wallets, and it was removed from next /accounts request, making it even more confusing.
Referencing the Coinbase Documentation https://developers.coinbase.com/docs/wallet/coinbase-connect/permissions
You can add the scope account = allto the permission scope. This will enable read access for all coins
https://www.coinbase.com/oauth/authorize?response_type=code&client_id=YOUR_CLIENT_ID&account=all&redirect_uri=YOUR_CALLBACK_URL&scope=wallet:accounts:read,wallet:transactions:read
After a day of scratching my head finally found my answer.
Attaching the accounts happens on a single wallet basis.
User needs to add BTC, XRP, ETC etc. accounts/wallets separately.
Each receives it's own TokenResponse with access and refresh token, which your application needs to manage.
Still do not understand what is the purpose of returning in /accounts endpoint remaining accounts with non usable id.
I am new to getting JSON into SQL Server 2016, I thought I had it down, but I notice that I am missing some details from the array, looking at the image, there are four address', but I saw there are some more address' missing for example Burrows Rd, and Urana RD. How can I make sure that all the address' captured?
https://i.stack.imgur.com/erzBV.jpg
#json nvarchar(max)
#json = N'{
"response": [
{
"application": {
"info": {
"dat_id": "010.2018.00036494.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-12-03T11:35:24+11:00",
"description": "Residence, Garage & Colorbond Shed, Demolition of Existing Residence & Tree Removal",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-26T00:00:00+11:00",
"determination_date": null,
"determination_type": "Pending",
"status": "In Progress",
"notification_start_date": null,
"notification_end_date": null,
"officer": "David Flood",
"estimated_cost": "Not applicable.",
"related_apps": [ ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2018.00036494.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "680 Centaur RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "Urana RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "Burrows RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
}
],
"events": [
{
"id": "3680347",
"timestamp": "2018-11-01T15:58:00+11:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3680348",
"timestamp": "2018-11-01T15:58:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3680349",
"timestamp": "2018-11-01T15:59:00+11:00",
"description": "Referal Parks & Recreation",
"event_type": "TREE",
"status": "COMP"
},
{
"id": "3680350",
"timestamp": "2018-11-01T16:00:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3683617",
"timestamp": "2018-11-21T14:59:00+11:00",
"description": "Site Assessment Inspection",
"event_type": "SITE",
"status": "PASS"
},
{
"id": "3685155",
"timestamp": "2018-12-03T11:37:00+11:00",
"description": "Assessment Report",
"event_type": "ASS3",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/163129",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=6hF7YEiv0qE=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC18/163139",
"title": "Site Plan and Elevations",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=1Gv3GVOIHCM=&fileName=Site+Plan+and+Elevations.PDF"
}
],
"people": [
{
"name": "Karyn Ford",
"role": "Applicant",
"contact": "6023 8287"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "017.2018.00036017.001",
"development_type": "Subdivision Only",
"application_type": "SCC",
"last_modified_date": "2018-12-03T10:19:25+11:00",
"description": "Roads, Sewer, Water & Drainage for Two (2) Lot Torrens Title Subdivisi on",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-11-14T00:00:00+11:00",
"determination_date": "2018-11-29T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "Sharna Holland",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/010.2018.00036017.001.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/017.2018.00036017.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "A",
"section": null,
"dpsp_id": "DP 161410"
}
},
"address": {
"street": "419 Hovell ST",
"suburb": "SOUTH ALBURY",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "A",
"section": null,
"dpsp_id": "DP 161410"
}
},
"address": {
"street": "Charles ST",
"suburb": "SOUTH ALBURY",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3683888",
"timestamp": "2018-11-23T14:03:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3683902",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3683903",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Building Surveyor 3",
"event_type": "BS3",
"status": "COMP"
},
{
"id": "3683904",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Trainee Town Planner",
"event_type": "TTP1",
"status": "COMP"
},
{
"id": "3684791",
"timestamp": "2018-11-29T14:36:00+11:00",
"description": "Collected Determination",
"event_type": "COLL",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/177392",
"title": "Subdivision Works Certificate",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=8qU1Pkawfvg=&fileName=Subdivision+Works+Certificate.PDF"
}
],
"people": [
{
"name": "Eslers Land Consulting",
"role": "Applicant",
"contact": "6021 1322"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "010.2016.00034838.001",
"development_type": "Residential - New multi unit",
"application_type": "DA",
"last_modified_date": "2018-12-03T09:36:09+11:00",
"description": "Twenty (20) Detached Self Contained Residences - Kensington Gardens Retirement Village",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2016-08-17T00:00:00+10:00",
"determination_date": "2016-10-24T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "Christopher Eldred",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.001.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.002.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.003.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.004.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.005.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.006.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.007.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.008.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.009.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.010.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.011.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.012.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2016.00034838.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "2",
"section": null,
"dpsp_id": "DP 874732"
}
},
"address": {
"street": "100 Table Top RD",
"suburb": "THURGOONA",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3583145",
"timestamp": "2016-08-17T14:13:00+10:00",
"description": "Further Information Requested",
"event_type": "INFO",
"status": "COMP"
},
{
"id": "3573096",
"timestamp": "2016-08-18T15:34:00+10:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3573097",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Building Surveyor 2",
"event_type": "BS2",
"status": "COMP"
},
{
"id": "3573098",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Plumbing Inspector",
"event_type": "PI",
"status": "COMP"
},
{
"id": "3573099",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3573100",
"timestamp": "2016-08-18T15:38:00+10:00",
"description": "Referral Environmental Planner",
"event_type": "ENV",
"status": "COMP"
},
{
"id": "3573103",
"timestamp": "2016-08-18T15:43:43+10:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3575194",
"timestamp": "2016-09-06T00:00:00+10:00",
"description": "Assessment Report",
"event_type": "ASS3",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC16/209893",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=sQkVV9rEsTU=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC16/209896",
"title": "Site Plan & Elevations",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=3dRqEZHzGeo=&fileName=Site+Plan+%26+Elevations.PDF"
},
{
"ref": "DOC16/211819",
"title": "Assessment Report",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=DVTQkQQqbns=&fileName=Assessment+Report.PDF"
},
{
"ref": "DOC16/240764",
"title": "Development Consent",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=TY+Y3zjyDKw=&fileName=Development+Consent.PDF"
}
],
"people": [
{
"name": "Kensington Gardens Lifestyle Estates",
"role": "Applicant",
"contact": "6049 3100"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "010.2018.00036468.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-11-30T17:17:25+11:00",
"description": "Residence, Garage and Retaining Walls",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-19T00:00:00+11:00",
"determination_date": "2018-11-26T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "David Flood",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/011.2018.00036468.001.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2018.00036468.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "218",
"section": null,
"dpsp_id": "DP 1228226"
}
},
"address": {
"street": "20 Stockman CRCT",
"suburb": "THURGOONA",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3678966",
"timestamp": "2018-10-25T10:47:00+11:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3678967",
"timestamp": "2018-10-25T10:48:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3678974",
"timestamp": "2018-10-25T10:51:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3681955",
"timestamp": "2018-11-01T15:49:00+11:00",
"description": "Site Assessment Inspection",
"event_type": "SITE",
"status": "COMP"
},
{
"id": "3684251",
"timestamp": "2018-11-27T10:24:00+11:00",
"description": "Collected Determination",
"event_type": "COLL",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/159026",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=MaiWkTs8V+g=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC18/159033",
"title": "Site Plan and Elevations and Superseded Plan",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=2xpqra8gNb0=&fileName=Site+Plan+and+Elevations+and+Superseded+Plan.PDF"
},
{
"ref": "DOC18/162569",
"title": "Assessment Report - Bldg Residential",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=bKYCMP01aJE=&fileName=Assessment+Report+-+Bldg+Residential.PDF"
},
{
"ref": "DOC18/168584",
"title": "Development Consent",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=SxGG/yKi68s=&fileName=Development+Consent.PDF"
}
],
"people": [
{
"name": "Alatalo Bros",
"role": "Applicant",
"contact": "02 6055 0180"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
}
],
"count": 4,
"pagination": {
"previous": null,
"next": 2,
"current": 1,
"per_page": 4,
"count": 24091,
"pages": 6023
}
}'
select *
from OPENJSON(#json, '$.response')
with
([lot] varchar(200) '$.application.locations[0].land_title_ref.torrens.lot',
[section] varchar(200) '$.application.locations[0].land_title_ref.torrens.section',
[dpsp_id] varchar(200) '$.application.locations[0].land_title_ref.torrens.dpsp_id',
[Street] varchar(200) '$.application.locations[0].address.street',
[suburb] varchar(200) '$.application.locations[0].address.suburb',
[state] varchar(200) '$.application.locations[0].address.state',
[postcode] varchar(200) '$.application.locations[0].address.postcode',
[geometry] varchar(200) '$.application.locations[0].geometry'
)
Try this:
select L.*
from OPENJSON(#json,'$.response') R
CROSS APPLY OPENJSON(R.[value], '$.application.locations')
with
(
[lot] varchar(200) '$.land_title_ref.torrens.lot',
[section] varchar(200) '$.land_title_ref.torrens.section',
[dpsp_id] varchar(200) '$.land_title_ref.torrens.dpsp_id',
[Street] varchar(200) '$.address.street',
[suburb] varchar(200) '$.address.suburb',
[state] varchar(200) '$.address.state',
[postcode] varchar(200) '$.address.postcode',
[geometry] varchar(200) '$.geometry'
) L
The locations is an array, so we need to use cross apply and OPENSJON to get all elements.
I'm having the hardest time figuring out how to display the following JSON file in my Angularjs repeat.
for the following JSON results, I thought I could simply display the title in an ng-repeat with the following:
<div ng-repeat="x in results">
{{x.data[0].title}}
</div>
But I'm not seeing results.
Here is the JSON:
{
"data": [
{
"id": 1,
"title": "Temp Title",
"description": "Temp Description",
"created_at": {
"date": "2016-03-15 07:10:17.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2016-03-15 07:10:17.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"user": {
"data": {
"id": 29,
"displayName": "chris.nakea",
"email": "chris.nakea#freshconsulting.com",
"join_date": 1458025279,
"profile": {
"data": {
"id": 29,
"displayName": "chris.nakea",
"avatar": null,
"firstName": null,
"lastName": null,
"bio": null,
"city": null,
"zipcode": null,
"state": null,
"country": null,
"latitude": null,
"longitude": null,
"avatars": {
"data": [
{
"id": "default_avatar.png",
"filename": "default_avatar.png",
"url": "https://cdn.band.dev/common/images/common/default_avatar.png",
"created_at": {
"date": "2016-03-15 00:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"images": {
"small": "https://cdn.band.dev/common/images/common/default_avatar_small.png",
"medium": "https://cdn.band.dev/common/images/common/default_avatar_medium.png",
"large": "https://cdn.band.dev/common/images/common/default_avatar_large.png"
}
}
]
},
"coverPhotos": {
"data": []
}
}
}
}
},
"category": {
"data": {
"id": 2,
"name": "Staff / Events",
"description": "Staff / Events",
"colorCode": "#242156",
"iconName": "icon-staff-events",
"iconCharacterCode": "c108"
}
},
"attachments": {
"data": [
{
"id": "1d3f96e2286c27ee599c9e49a0c33da0",
"filename": "man.jpg",
"url": "https://api.band.dev/v1/file/1d3f96e2286c27ee599c9e49a0c33da0",
"created_at": {
"date": "2016-03-15 07:10:17.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"images": {
"small": "https://api.band.dev/v1/file/50af58b3d52d8629e9f5c4d0dcdd5181",
"medium": "https://api.band.dev/v1/file/51535d38f7b3cd82313eac2414059d83",
"large": "https://api.band.dev/v1/file/a7be1dada18e4041cf48aea377cafa29"
}
}
]
}
},
{
"id": 2,
"title": "Temp Title",
"description": "Temp Description",
"created_at": {
"date": "2016-03-15 07:12:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2016-03-15 07:12:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"user": {
"data": {
"id": 29,
"displayName": "chris.nakea",
"email": "chris.nakea#freshconsulting.com",
"join_date": 1458025279,
"profile": {
"data": {
"id": 29,
"displayName": "chris.nakea",
"avatar": null,
"firstName": null,
"lastName": null,
"bio": null,
"city": null,
"zipcode": null,
"state": null,
"country": null,
"latitude": null,
"longitude": null,
"avatars": {
"data": [
{
"id": "default_avatar.png",
"filename": "default_avatar.png",
"url": "https://cdn.band.dev/common/images/common/default_avatar.png",
"created_at": {
"date": "2016-03-15 00:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"images": {
"small": "https://cdn.band.dev/common/images/common/default_avatar_small.png",
"medium": "https://cdn.band.dev/common/images/common/default_avatar_medium.png",
"large": "https://cdn.band.dev/common/images/common/default_avatar_large.png"
}
}
]
},
"coverPhotos": {
"data": []
}
}
}
}
},
"category": {
"data": {
"id": 2,
"name": "Staff / Events",
"description": "Staff / Events",
"colorCode": "#242156",
"iconName": "icon-staff-events",
"iconCharacterCode": "c108"
}
},
"attachments": {
"data": [
{
"id": "a93cf8df7b60686e7ca6884d0ce353c8",
"filename": "man2.jpg",
"url": "https://api.band.dev/v1/file/a93cf8df7b60686e7ca6884d0ce353c8",
"created_at": {
"date": "2016-03-15 07:12:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"images": {
"small": "https://api.band.dev/v1/file/cd04551395a355f4792fb85833156741",
"medium": "https://api.band.dev/v1/file/4ff543cd8f5055bfecd703dedaee6d87",
"large": "https://api.band.dev/v1/file/5cdd9a0c3650228e0b93f9c6cd1404df"
}
}
]
}
}
]
}
You can just remove the datap[0] part and get the output
<div ng-repeat="x in results.data">
{{x.title}}
</div>
Output:
Temp Title
Temp Title
if you want to filter then you can do it by
<div ng-repeat="x in results.data | filter: { id: '1' }">
{{x.title}}
</div>
Output:
Temp Title
<div ng-repeat="item in data">{{item.title}}</div>
And in your controller, bind the json to the scope.
$scope.data = jsonData.data;
Here's a fiddle for you - jsFiddle
<div ng-repeat="x in results.data">
{{x.title}}
</div>
https://jsfiddle.net/nvqf8oo7/6/
Thank you all for responding. I finally figured out that the reason I wasn't seeing anything was because I am using ui.bootstrap's modal and I was out of scope.
I resolved this by moving the ng-repeat out of the modal, but I could have also tried to work with the modal scope itself.