Iterating through JSON format - json

i have the following problem: i am sending a JSON File from a webservice into a extension to Qlik Sense and i am getting the following response:
"{"rownumber":1,"ID":1}{"rownumber":2,"ID":2}"
The type of the response is string. My question is how can i change the format to iterate through each element of this.
I have already tried the JSON.parse(result) and JSON.stringify(result) functions but the result was nothing that i can work with. Last one changed the
result to:
"{"rownumber":1,"ID":1}{"rownumber":2,"ID":2}"

Related

how to parse dynamic json object in Typescript

I have a json object in my typescript which is returned from server side. One of the keys is dynamic. How do I parse and extract the value for that key.
Ex: serverResponse.detailsLMN.allList
Ex :serverResponse.detailsLMN.deleteList
In the above , 'LMN' is dynamic.
It can be serverResponse.detailsLMN.allList or serverResponse.detailsPQR.allList.
Assuming,
const temp = 'LMN' or 'PQR', how can I use temp to parse JSON object here.
Like : serverResponse.details{temp}.allList
Not sure if I understood your question correctly. But try doing
let data = JSON.parse(serverResponse);
((JSON.stringify(serverResponse)).includes("LMN")) ? serverResponse.detailsLMN.allList
: serverResponse.detailsPQR.allList
^The above code is the same as the if statement. If you don't know the ES6 ternary conditional statement then here's a link:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
To parse, simply use JSON.parse(). To extract the value, since I can't see the format of the output, it's better to console.log(serverResponse) the whole response and then walk through the Object in Chrome console to see how to get to your specific value.

how to parse a json text on angular array of object .? and display it on ng 2 smart table

I'm doing the maintenance of an angular website, I have a problem of display in the ng2 smart table , in a column it displays the json of an object, this is the error that the developer has made by receiving the list of transaction where the user and items are a json text,
how can I parse them
ps this is the code :
this.data.doData('transaction','get').subscribe({
next:res=>{
console.log(res);
this.dataSource = [...res['transactions']]
console.log(this.dataSource)
},error:err=>{
console.log(err);
}
})
So actually you are getting the JSON string. To use it just do JSON.parse(items) and JSON.parse(user) and you will get the parsed JSON (array for the items and pbject for the user)
You can also use map in your service file and handle this parsing their so when you subscribe to the data in your component's ts file you will get the parsed form.
UPDATE:
Look at the quotes (quotes matching you would know from basic rules of strings, i.e. either single or double should be enclosing the main string). So when you were JSON parsing the string it wasn't taking it correct format to parse it.

How do I parse a JSON from Azure Blob Storage file in Logic App?

I have a JSON file in Azure Blob storage that I need to parse and insert rows into SQL using the Logic App.
I am using the "Get Blob Content" and my first attempt was to then pass to "Parse JSON". It returns and error": InvalidTemplate. Unable to process template language expressions in action 'Parse_JSON' inputs at line '1' and column '2856'"
I found some discussion that indicated that the content needs to be converted to a string so I used "Compose" and edited the code as suggested to
"inputs": "#base64ToString(body('Get_blob_content').$content)"
This works but then the InvalidTemplate issue gets pushed to the Parse function and I get the InvalidTemplate error there. I have tried wrapping the output in JSON expression and a few other things but I just can't get it to parse.
If I take a sample or even the entire JSON and put it into the INPUT of the Parse function it works without issue but it will not accept the blob content as JSON.
The only thing I have been able to do successfully from blob content is to take it as a string and update a row in SQL to later use the OPENJSON in SQL...but I run into an issue there that is for another post.
I am at a loss of what to do.
You don't post much information about your logic app actions, so maybe you could refer to my flow design. I test with a json data with array.
The below is my flow picture. I'm not using compose action, and use decodeBase64(body('Get_blob_content')['$content']) as the Parse Json content.
And if select property from the json, you need set the array index. I set a variable to get a value 'body('Parse_JSON')1['name']'.
you could have a try with this, if still fail, please provide more information or some sample to let us have a test.

Karate - How to compare shuffled json with response?

I am trying to compare response with expected json stored already as a file. There are few elements in response where the order is different in response. Tried below code but still failing:
def expected_response = read('classpath:api/template/test.json')
And match response == '#(^*expected_response)'
Also tried
And match response contains any expected_response
Both cases error comes as actual does not contains expected. Kindly help to resolve.

Confused with JSON data and normal data in Django ajax request

I read about JSON from internet but still i have not got the grasp of it. I am reading this article
http://webcloud.se/log/AJAX-in-Django-with-jQuery/
I could not understood the first part where the function is using JSON
def xhr_test(request, format):
if request.is_ajax():
if format == 'xml':
mimetype = 'application/xml'
if format == 'json':
mimetype = 'application/javascript'
data = serializers.serialize(format, ExampleModel.objects.all())
return HttpResponse(data,mimetype)
# If you want to prevent non XHR calls
else:
return HttpResponse(status=400)
My Main Problems are
From where the function is getting format variable
Does format is json mean that data given to function is json or data which will be recived is json
Can anyone give me simple example that what will be the ouput of this function
data = serializers.serialize(format, ExampleModel.objects.all())
How will I use that data when i get that response in jquery function
If i don't use JSON in above function then how will the input and response back will chnage
Thanks
From where the function is getting format variable
In practice, there are lots of ways this format could be populated. HTTP provides an Accept: header that requests can use to indicate the preferred Content-Type for the response. On the client, you might use xhr.setRequestHeader('accept', 'application/json') to tell the server that you want your response in json format. In practice, though, very few frameworks actually do this. This being django, arguments to view functions are usually set in the urlconf, you might craft a urlconf like this:
urlpatterns = patterns('',
# ...
(r'^xhr_test.(?<format>.*)$', 'path.to.xhr_test'),
)
2 . Does format is json mean that data given to function is json or data which will be recived is json
This particular view doesn't do anything at all with the request body, and is certainly providing a response body in the supplied format
4 . How will I use that data when i get that response in jquery function
Depending on how complicated your request needs to be, you can use jQuery.getJSON, which will pass your callback with regular JavaScript objects that result from parsing the JSON. If you need to do a bit more work to get the request right, you can use jQuery.parseJSON to process the json data, and that will return the same JavaScript objects.
From the urlconf, just like it says in the article right below it.
The query set will be serialized as JSON.
It will be the query set represented as either XML or JSON. python manage.py shell is your friend.
You will decode it, then iterate over it.
You'll need to find some other format to serialize it in instead.