Say I have the following JSON object, how can I access, directly (without iterating over the entire array of items), a subarray item of it, using Delphi and JsonDataObjects
{"menu": {
"header": "SVG Viewer",
"items": [
{"id": "Open"},
{"id": "OpenNew", "label": "Open New"},
null,
{"id": "Help"},
{"id": "About", "label": "About Adobe CVG Viewer..."}
]
}}
What is the Delphi code to directly access the subarray with id = "About" and read the label property?
Related
I'm using angular-datatables to display NoSQL de-normalized data in grid for visualization purpose,
I have few complex nested json objects and wanted to display specific cell with prettified json with inbuilt JsonPipe
I'm using datatables with data binding as
<table id="dtTable" datatable [dtOptions]="data"></table>
Sample JSON
[
{
"Id": "1",
"Name": "Test",
"Account": {
"Id": "12",
"Name": "Stackoverflow",
"Contact": {
"Id": "23",
"Name": "stack exchange",
"Phone1": "712426",
"Phone2": "490591",
"Address": {
"Id": "12",
"Name": "Address 1",
"AddressType": "commercial"
}
}
},
"CreatedBy": {
"Id": "123",
"Name": "User 1"
},
"CreatedDate": "2022-04-11T10:42:28.7525823Z",
"ModifiedBy": {
"Id": "124",
"Name": "User 2"
},
"ModifiedDate": "2022-04-11T10:42:28.7525823Z"
},
{
...
},
...
]
want to render as
Id
Name
Account
Created By
1
Test
{ Pretified JSON}
{Json}
Do we have any option to render entire json content in specific column cell of tables using angular-datatables? or do we have any other option other than json pipe to display formatted json content in angular-datatables
Yes, you can use the build in pipe as you mentioned:
In HTML directly:
...
<td>{{accountInfo | json}}</td>
...
Or in TS file using the transform function.
...
this.accountInfo = this.jsonPipe.transform(response.accountInfo)
...
If you use the transform function, be sure that the Pipe is imported properly in the TS file.
Using VBA-JSON v2.0.1 in excel VBA
Here is the JSON response I get from API query
{
"currency": {
"code": "USD",
"name": "US Dollar",
"prefix": "$",
"postfix": null
},
"products": [
{
"product_id": xxxxx,
"model_code": "xxxxx",
"quantity": 1,
"price": "45.60",
"total": "45.60",
"retail_price": "63.84"
}
],
"shipping": [
{
"name": "UPS",
"price": 43.83,
"delivery": "3 -10 Days delivery"
},
{
"name": "DHL",
"price": 20.29,
"delivery": "2-6 days"
},
{
"name": "FedEx",
"price": 31.46,
"delivery": "2-6 days"
},
{
"name": "EMS",
"price": 25.74,
"delivery": "7 - 25 Days delivery"
},
{
"name": "Air Mail",
"price": 11.85,
"delivery": "10 - 25 Days delivery"
}
]
}
Here is a part of my code to parse the price from "Air Mail" element.
result = objHTTP.responseText
Dim Json As Object
Dim resultAirmailprice As String
Set Json = JsonConverter.ParseJson(result)
resultAirmailprice = Json("shipping")(5)("price")
Cells(2, 2).Value = resultAirmailprice
The code runs fine when the "Air Mail" element is in (5) of "shipping" element. The problem is sometimes there are no "UPS" and "Air Mail" elements, so I got an error.
How to write code to parse the "Air Mail" price and if not exists, parse from "EMS" price(or the cheapest price out of all)?
Looking at Json parser code, it returns a Dictionary Object that contains other Dictionary Objects (sub keys) and, for arrays, Collection Objects. In the Json I see that "shipping" is an array and so the parser returns a Collection Object.
So you can use all the Collection members and methods to manipulate and access it. In particular, you can use Json("shipping").Count to check how many elements the Shipping collection has. Or you can iterate over the collection with For each x in Json("shipping").
To check whether you have a Dictionary or a Collection, you could use the TypeName function or the TypeOf..Is operator.
I have a JSON object:
[
{
"name": "abc",
"category": "developer",
"Address": [
{
"street": "xxx"
},
{
"street": "yyy"
}
]
},
........
]
I am using builder pattern to build Address as well as the object of this array. How can I append one more street in Address in this structure (given name is unique across different objects of this array.
Note: As I am using builder pattern so I can not access fields of
this object using getters.
I'm aware of this question but I don't believe that there is no solution with standars component. I'm using Talend ESB Studio 5.4.
I have to parse a JSON string from a REST web service into multiple output, and add them to a database.
Database has two tables:
User (user_id, name, card, card_id, points)
Action (user_id, action_id, description, used_point)
My JSON Structure is something like that:
{
"users": [
{
"name": "foo",
"user_id": 1,
"card": {
"card_id": "AAA",
"points": 10
},
"actions": [
{
"action_id": 1,
"description": "buy",
"used_points": 2
},
{
"action_id": 3,
"description": "buy",
"used_points": 1
}
]
},
{
"name": "bar",
"user_id": 2,
"card": {
"card_id": "BBB",
"points": -1
},
"actions": [
{
"id": 2,
"description": "sell",
"used_point": 5
}
]
}
]
}
I have tried to add a JSON Schema Metadata but it is not clear to me how to "flat" the JSON. I have tried to look at tXMLMap, tExtractJSONFields.. but no luck till now.
I also had a look at tJavaRow but I don't understand how to make a Schema for that.
It's a pity because till now I'm loving Talend! Any advice?
You can save a json file in your disk, then create new json file in the metadata of Talend studio, the wizard retrieve the schema for you, after saving, you ca, copie schema in the generic schema of the metadata, and it's done, use that generic schema where you want, this is how to use generic schema in the tRestClient component:
I am trying to create a domain and uploading a sample data which is like :
[
{
"type": "add",
"id": "1371964",
"version": 1,
"lang": "eng",
"fields": {
"id": "1371964",
"uid": "1200983280",
"time": "2013-12-23 13:00:26",
"orderid": "1200983280",
"callerid": "66580662",
"is_called": "1",
"is_synced": "1",
"is_sent": "1",
"allcaller": [
{
"sno": "1085770",
"uid": "1387783883.30547",
"lastfun": null,
"callduration": "00:00:46",
"request_id": "1371964"
}
]
}
}]
when I am uploading sample data while creating a domain, cloudsearch is not taking it.
If I remove allcaller array then it takes it smoothly.
If cloudsearch does not allowing object arrays, then how should I format this json??
Just found after searching on aws forums, cloudsearch doesnot allow nested json (object arrays) :(
https://forums.aws.amazon.com/thread.jspa?messageID=405879񣅷
Time to try Elastic search.