Angularjs fetching data - angularjs

I'm new to angularjs. I have a json.
{
"first": {
"content": {
"admin.nv.example.com": {
"start": "2016-02-24 06:04:12.772141"
}
}
}
}
This is my JSON response i want to obtain value of property name (start) in this whole response but whenever i try to access this property value by first.content.admin.example.com.start
it shows error:Cannot read property 'nv' of undefined(angularjs)

You should use a different syntax to access the dotted property name. In fact it is better to avoid names like 'admin.nv.example.com' containing dots.
This should work:
first.content['admin.example.com'].start

use first.content['admin.nv.example.com']

You should use the ["admin.nv.example.com"] notation.

You should understand the proper way of writing JSON. But you should use like this:
test['first']['content']['admin.nv.example.com'];
JSON formats

Related

How sort this json format in react native using map function

I have the following JSON format
{
"name":"xyz",
"age-group":"bb"
}
How to get sort out this JSON
I use the following code
const array = [{ "name":"xyz", "age-group":"bb"} ]
array.map((element) => {
Console.log(element.age-group)
});
I got an error:
Can't find variable: group
1st thing is you can't map object.
and in your case you set json object in array and then you are maping it.
so it must be like:
array[0].name;
but in second property, it has hyphen which looks like "age-group" to access object property containing hyphen is:
array[0].obj["age-group"] //this is return `bb`
so in your code it will be:
array.map((element) => {
console.log(element.obj["age-group"])
});
to access object property with hyphen(-) you need to use notation with square brackets.

Gatling - Extract Json value from previews request

I'm new in Gatling, and trying to get value from json key.
This check give me labels:
.check(jsonPath("$[1].ppp[1].label").saveAs("label"))
In this request i got all json data like this
[
{
"id":258,
"code":"D00CC3056",
"label":"Test-0"
},
{
"id":260,
"code":"D00RR148",
"label":"Test-1"
}
]
From this Json, i need to get code value from a specific label, to use it in request after.
Something like : get code where label is "Test-1".
I've trying this but doesn't works:
.exec(
http("request_3:GET_/api/code")
.get("/api/code")
.check(status.is(200))
.check(jsonPath("$..[*].code").find("{$label}").saveAs("code"))
)
I don't know how to do this.
Any help ?
With JMESPath that you should really learn and that Gatling supports:
.check(jmesPath("[?label == 'Test-1'].code").saveAs("code"))

Azure logic apps: Nullable JSON values not available as dynamic content

I'm building a logic app that pulls some JSON data from a REST API, parses it with the Parse JSON block, and pushes it to Azure Log Analytics. The main problem I'm hitting is an important JSON field can either be an object or null. Per this post I changed the relevant part of my JSON schema to something like this
"entity": {"type": ["object", "null"] }
While this works, I'm now no longer to access entity later in the logic app as dynamic content. I can access all other fields parsed by the Parse JSON block downstream in the logic (that don't have nullable field). If I remove the "null" option and just have the type set to object, I can access entity in dynamic content once again. Does anyone know why this might be happening and/or how to access the entity field downstream?
Through the test, if we use "entity": {"type": ["object", "null"] }, we really cannot directly select entity in dynamic content.
But we can use the following expression to get the entity:
body('Parse_JSON')?['entity']
The test results seem to be no problem:
For a better understanding, let me cite a few more examples:
1. If your json is like this:
{
"entity": {
"testKey": "testValue"
}
}
Your expression is like this:
body('Parse_JSON')?['entity']
2. If your json is like this:
{
"test": {
"entity": {
"testKey": "testValue"
}
}
}
Your expression should like this:
body('Parse_JSON')?['test']?['entity']

How to fetch xml attribute value in liquid template - XML to JSON Liquid

I am trying to fetch the xml attribute value using liquid template. Examples are as below.
XML example:
<ns0:root xmlns:ns0="http://customnamespace.com" xmlns:ns1="http://customnamespace2.com">
<ns1:product>
<ns1:name QualifierID="std.lang.all" >TV</ns1:name>
<ns1:price>499.9</ns1:price>
</ns1:product>
</ns0:root>
Liquid Template used:
{
"name": "{{content.product.name['QualifierID']}}",
"price": "{{content.product.price}}",
}
Output expecting :
{
"name": "std.lang.all",
"price": "499.9"
}
I tried couple of ways but not able to fetch the xml attribute value. it gives me empty value for name.
Best Regards,
Suraj
According to some test, it seems we can't get the attribute(QualifierID) value of the xml by liquid. And I also can not find any useful information about getting attribute value of xml by liquid. But I can provide a workaround for your reference, please refer to my logic below.
1. I initialize a variable named xmlString and set the value with your xml data to simulate your situation.
2. I initialize another variable named jsonString and set its value with converting the xmlString to json.
3. After that, use "Parse JSON" action to parse the jsonString we get above. And then use "Compose" action to compose the json data which you expected.(The schema in "Parse JSON" was generated by the result from "Initialize variable 2").
Hope it helps~

Can i return an array of "number, number" in json format?

i have a list of lat/long objects on my server.
eg.
public class LatitudeLongitude
{
public float Latitude;
public float Longitude;
}
simple.
now, can i return a collection of these, in json format .. BUT ... i do not want to list the key, just the values.
This means the normal result would be something like ...
{ { lat: 111, long : 222 }, { lat: 333, long : 444 } } ..
but i'm hoping for...
{ {111, 222}, {333, 444} ..... }
{ {obj1.Lat, obj1.Long}, {obj2.Lat, obj2.Long} ... etc. ... }
Is this possible? I mean, i can make that string on the server side easily. But is that a correct JSON output format?
Can someone please confirm, etc.
cheers :)
PS. I hardly know any Json, so please don't hesitate to correct my poor examples above.
Use JSON arrays:
[ [111, 222], [333, 444], ... ]
Ayman's proposal isn't quite correct JSON syntax. As an object {..} is always composed of fields having a name. So we again would have object with 2 fields of type 'array' that don't have a name -> not valid json for an object.
There is a very good description of how a json string can look like at www.json.org. Looking at this description you'll see an object is not allowed without a name String for a field so this {111,222} is not a valid object in json, but this is valid [111,222] array. This is not a valid object {[111,222]} but this is {array1 : [111,222]}.
I guess what you actually want is most likely an array of arrays like this not encapsulated as an object.
[[111,222],[333,444]].
This approach would give you the choice to add as much arrays of lat/long as you like to the enclosing array and at the same time you can process the inner arrays no matter what size the outer array is with an javascript loop.
Hope that helped.
cheers
Michael
If you need to access it using the keys in JSON, you'll need to specify it (or use a JS to convert arrays to objects on the client side). Otherwise, arrays should work:
var json = [ [123, 456], [234, 567] ];
var convertedJson = [];
for (i = 0; i < json.length; ++i) {
var thisObj = new Object();
thisObj.latitude = json[i][0];
thisObj.longitude = json[i][1];
convertedJson[i] = thisObj;
}
But is that a correct JSON output
format?
You can paste in JSON at jslint.com to validate your JSON
The ASP.NET MVC JSON serializer should convert a IList<LatitudeLongitude> to something like this:
[{"Latitude":111,"Longitude":222},{"Latitude":333,"Longitude":444} .. ]
I believe that under the ASP.NET MVC JSON serializer is just a hot-wired .NET core Javascript serializer.
I dont think it's possible from .NET using a serializer. Prob need to render the string manually.

Resources