Json Array from spring Blank in the table using angularJS - json

i have json array from spring rest like this:
var v=[{"id":"A1",
"name":"Bobi",
"age":27,
"supervisor":{
"id":"S1",
"name":"Doni",
"age":27,
"supervisor":null
}
},
{
"id":"B1",
"name":"Thomas",
"age":27,
"supervisor":{
"id":"C1",
"name":"Ronald",
"age":27
"supervisor":null
}
},
"C1",
"S1"
]
i want to show it in the table using angularJS, but in 3rd and 4th row always blank.
How i can show "C1" and "S1" ?

Though your JSON is valid but C1 & S1 are not in the same format as A1 & B1.
So, if you want to show all values in the same table in same format, then the JSON should also have to be of the same format.
Having them in the same format in API is far much easier then formatting the JSON in angular and making it work like the other objects.
Hope this helps.

Related

How can I get Boomi to return valid JSON

I am querying records from Salesforce and trying to return the record set as a JSON array of records.
Unfortunately, it returns every record as if it was a single record as the complete JSON rather than an array element in the same JSON object.
{
"AppointmentID": "a046g00000Nyk6oAAB"
}{
"AppointmentID": "a046g00000NyjhfAAB"
}{
"AppointmentID": "a046g00000NygSfAAJ"
}
There are no commas between the records. So I built the array into the JSON response and get:
{
"Appointments": [
{
"AppointmentID": "a046g00000Nyk6oAAB"
}
]
}{
"Appointments": [
{
"AppointmentID": "a046g00000NyjhfAAB"
}
]
}{
"Appointments": [
{
"AppointmentID": "a046g00000NygSfAAJ"
}
]
}
and it sends each record as the entire JSON template rather than a element of the array. Again, it also does not send commas back between the elements. I can work with a less than ideal structure but I need valid JSON returned.
Lastly, I tried to modify the results with a Data Process Shape using s Search and Replace
searching for: \}\{
replacing with \}\,\{
trying for force a comma between the braces, but the search never finds any matches even though this is a valid Javascript regex search.
Any suggestions would be greatly appreciated.
Final/Fixed Map
It's likely that the destination profile is incorrect and that you manually created the JSON profile. I would write the JSON out that you're expecting with all of the fields and then import (when you open the JSON profile, it's a blue button in the top right).
Also, Salesforce usually returns each record as 1 document and not combined. So, it's likely multiple documents are coming out of the map and you'll need to do a combine (data process shape).

How to transform Azure Search query result into a table / spreadsheet format

I use blob storage to save data from my Botframework v4 Chatbot.
When I query the results with Azure Search I get this:
{
"#odata.context": "https://roboadvisorydatasearch.search.windows.net/indexes('azureblob-index')/$metadata#docs(*)",
"value": [
{
"#search.score": 1,
"content": "{\"id\":\"3470100\",\"realId\":\"3470100\",\"document\":{\"name\":\"pierre\",\"age\":18,\"gender\":\"weiblich\",\"education\":\"Abitur\",\"complete\":true,\"roundCounter\":1,\"riskchoices\":[\"B\"],\"riskAssessmentComplete\":true,\"riskDescription\":\"höchst risikoliebend\",\"order\":[\"0\",\"2\",\"1\"],\"choice\":\"Plus GmbH\",\"follow\":true,\"endRepeat\":true,\"eTag\":\"\\\"0x8D6AB012AE82E05\\\"\",\"loss1\":\"ACG GmbH\",\"win1\":\"Plus GmbH\",\"win2\":\"Breen GmbH\",\"payout\":\"Du bekommst 7000 Geldeinheiten = 7,00€ ausgezahlt.\"}}\n"
},
{
"#search.score": 1,
"content": "{\"id\":\"159287\",\"realId\":\"159287\",\"document\":{\"name\":\"A18\",\"age\":18,\"gender\":\"weiblich\",\"education\":\"Abitur\",\"complete\":true,\"roundCounter\":7,\"riskchoices\":[\"A\",\"A\",\"A\",\"A\",\"A\",\"A\",\"B\"],\"riskAssessmentComplete\":true,\"riskDescription\":\"risikoavers\",\"order\":[\"1\",\"2\",\"0\"],\"choice\":\"ACG GmbH\",\"follow\":false,\"endRepeat\":true,\"eTag\":\"\\\"0x8D6A94E40672463\\\"\",\"win1\":\"Breen GmbH\",\"win2\":\"Plus GmbH\",\"loss2\":\"ACG GmbH\",\"payout\":\"Du bekommst 5000 Geldeinheiten = 5,00€ ausgezahlt.\"}}\n"
}
]
}
What I want is a table / spreadsheet (that I can use in Excel for example). Each result should be in a row and the colums should be the keys from the JSON inside each "content". This website works great, but only if I insert the object inside "content". But doing this for each row would be a lot of work.
Our API does not support returning results in csv format. You need to convert response by yourself.
Sample solution for C#: JSON string to CSV and CSV to JSON conversion in c#
Sample solution for JavaScript: How to convert JSON to CSV format and store in a variable

How can I find the row & column in a JSON String identified by a JsonPath?

Suppose I have a JSON string like this example:
[
{
"name": "John"
},
{
"name": "Jane"
}
]
Using JSONPath I want to select the second name like this:
[1].name
However, I am not interested in the name's value but rather in the row & column of the entire second name key-value pair as they appear in the String. In this example, the expected result when written as a JSON would be:
{
"row": 5,
"column": 4
}
Alternatively, the index within the String would be fine as well. Note that I don't require the result to be a JSON. Note also that this should work with any formatting of the JSON.
I have thought about constructing a regular expression but this might be fragile if the key's name "name" also appears as text in values.
I am using Jayway JSONPath in my Java backend but a solution with a different JSONPath library, or one in JavaScript using an Node.js compatible library would also be fine.

Order of performing sorting on a big JSON object

i have a big json object with a list of "tickets". schema looks like below
{
"Artist": "Artist1",
"Tickets": [
{
"Id": 1,
"Attr2Array": [
{
"Att41": 1,
"Att42": "A",
"Att43": null
},
{
"Att41": 1,
"Att42": "A",
"Att43": null
},
],
.
.
.
(more properties)
"Price": "20",
"Description": "I m a ticket"
},
{
"Id": 4,
"Attr2Array": [
{
"Att41": 1,
"Att42": "A",
"Att43": null
},
{
"Att41": 1,
"Att42": "A",
"Att43": null
},
],
.
.
.
.
(more properties)
"Price": "30",
"Description": "I m a ticket"
}
]
}
each item in the list has around 25-30 properties (some simple types, and others complex array as nested objects)
i have to read the object from an api endpoint and extract only "ID" and "Description" but they need to be sorted by "Price" which is an int for example
In what order shall i proceed with this data manipulation
Shall i use the json object, deserialised it into another object with just those 2 properties (which i need) and THEN perform sort "asc" on the "Price"?
Please note that after i have the sorted list i will have to convert it back to a json list because the front end consumes a json after all.
What i dont like about this approach is the cycle of serialisation and deserialisation that happens
or
I perform a sort on the json object first (using for example a binary/bubble sort) and then use the object to create a strongly typed (deserialised) object with just those 2 properties and then serialise it back to pass to the front end
I dont know how performant the bubble sort will be and if at all i will get any gain in performance for large chunks of data processing.
I also need to keep in mind that this implementation can take into account other properties like "availabilitydate" because at a later date, this front end could add one more filter like "availabilitdate" asc
any help is much appreciated
thanks
You can deserialize your JSON string (or file) using the Microsoft System.Web.Extensions and JavaScriptSerializer.DeserializeObject.
First, you must have classes associated to your JSON. To create classes, select your JSON sample data and, in Visual Studio, go to Edit / Paste Special / Paste JSON As Classes.
Next, use this sample to deserialize a JSON string to typed objects, and to sort all Tickets by Price property using Linq.
String json = System.IO.File.ReadAllText(#"C:\Data.json");
var root = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Rootobject>(json);
var sortedTickets = root.Tickets.OrderBy(t => t.Price);

Get value of json string

[
{
"type": "spline",
"name": "W dor\u0119czeniu",
"color": "rgba(128,179,236,1)",
"mystring": 599,
"data": ...
}
]
I am trying to access this json as json['W doręczeniu']['mysting'], and I get no value why is that?
You're trying to access the index "W doręczeniu" but that's not an index it's a value. Also, what you seem to have is an array of JSON objects.
The [ at the start marks the array, the first element of which is your JSON object. The JSON obj begins with the {
You're also trying to use a [ ], but JSON values are accessed with the dot operator.
I'm not sure which index you're actually trying to access, but try something like this:
var x = json[0].mystring;
The value of "W doręczeniu" is not a key, so you cannot use it to get a value. Since your json string is an array you'll have to do json[0].nameto access the first (and only) element in the array, which happens to be the object. Of course, this is assuming json is the variable you store the array into.
var json = [{"type":"spline","name":"W dor\u0119czeniu","color":"rgba(128,179,236,1)","mystring":599}];
console.log(json[0].mystring); //should give you what you want.
EDIT:
To get the last element in a js array, you can simply do this:
console.log( json[json.length -1].mystring ); // same output as the previous example
'length - 1' because js arrays are indexed at 0. There's probably a million and one ways to dynamically get the array element you want, which are out of the scope of this question.