Angularjs JSON with filter - json

How to pass a service json data(which already getting from services.js) to filter(filter.js)?
Example:JSON data:
{"name" :"stackoverflow"}
Services.js:
Here i have written service to get json data
{"getjsondataservice" }
Controller:
using "getjsondataservice" service here.
{}i need to get "getjsondataservice" service to filter.jsFilter:{}how should i write that filter?

In output code you should write filter name:
{{ stackoverflow | filter }}
Then the filter will work and you will receive the filtered variable.

Related

Azure Logic App - Parse JSON with dynamic key/name

just want to know if and how I can parse a HTTP response with a dynamic name in a JSON?
I used the Azure Management API to receive the managed identities (system- and user assigned managed identities) to receive all managed identities.
With a foreach I am iterating the results.
If a resource has a system assigned managed identity and user assigned managed identity, the response looks like this:
{
"principalId": "<principalId1>",
"tenantId": "<tenantId>",
"type": "SystemAssigned, UserAssigned",
"userAssignedIdentities": {
"/subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<userAssignedIdentitiesName>": {
"principalId": "<principalId2>",
"clientId": "<clientId>"
}
}
}
Now, I would like to get the <principalId2>.
Unfortunately, the Name of the object is dynamic related to the scope of the resource /subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<userAssignedIdentitiesName>.
How can I parse the JSON to receive the needed <principalId2>?
For all other responses I can easily use the Data operations Parse JSON with the payload I inserted from the HTTP response.
Is there a way to use a wildcard? Otherwise, could I somehow just select the first object of userAssignedIdentities to receive the needed value?
Ok, this should work for you. This is the flow I tested with ...
Initialise JSON
Your JSON as a string, how you do that in your solution may differ slightly.
Initialize XPath Result
Defined as an Array and the expression is ...
xpath(xml(json(concat('{ root: ', replace(variables('JSON'), 'PrincipalId', 'principalId'), '}'))), '(//principalId)[2]')
Initialize Result
A bit more work again but defined as a String and the expression is ...
array(xpath(xml(base64ToString(variables('XPath Result')[0]?['$content'])), '//text()'))[0]
The end result should be your value ...

How to make my API method GET through id connect with my html form on view - Laravel 8

Hi guys! Hope you can help me out with this:
- So i have this code in my API controller:
API controller
-This route in my API route:
API route
-And this on my view (only the part im having problems with):
view
ps: the line of form action is correctly seperated, where it says ..."get"action... , i just put it like that here because of space.
Q.: When i use the route to GET all the data from the database my output is a json file with everything in it, but when i use this route to only get the data of one movie (in my case it's a DB of movies) the output is an empty JSON file, even tho the method works on postman. Can you help me out ? Thank you
MY OUTPUT , of the empty json file
Using a form with getting method the form data will be appended in Query Parameter.
/search/titulo -> it is wrong. the titulo word is not dynamic keyword.
You get your dynamic search keyword in titulo keyword after ?titulo=avenger
Use the request function to get the query parameter value
$seach = request()->get('titulo');
You should change your search to get a route to only /search?keyword=avenger like this.
Full example
In your blade file
<form action"{{ route('search') }}" method="get">
<input name="titulo">
<button type="submit">Search</button>
</form>
In your route file
Route::get('/search', [YourControllerName::class, 'methodname'])->name('search');
In your controller File: Where you handle the searched keyword
public function search() {
$search = request()->get('titulo'); // Get the searched keyword value
$result = ModelName::where('titulo', 'like', '%'.$search.'%')->get();
return $result;
}

How do I extract JSON data from a raw.github URL and store it in a variable?

Let's say that I have a JSON file called data.json in Github. I can view it in raw in a Github URL like this: https://raw.githubusercontent.com/data.json (This is a hypothetical URL. It's not real)
And let's say that URL contains JSON data like this:
"users_1": [
{
"id": 1234,
"name": "Bob"
},
{
"id": 5678,
"name": "Alice"
}
]
How do I extract the whole JSON data from that URL and store it in a variable in a Cypress test? I know that Cypress doesn't really use Promises, so I'm finding it difficult to implement this. So far I got this in Typescript:
let users; // I want this variable to store JSON data from the URL
const dataUrl = "https://raw.githubusercontent.com/data.json";
cy.request(dataUrl).then((response) => {
users = JSON.parse(response); // This errors out because response is type Cypress.Response<any>
})
I'm planning to do something like this in the future for my project when migrating from Protractor to Cypress. I have a Protractor test that extracts JSON data from a Github file and stores it a variable by using a Promise. I want to do the same kind of task with Cypress.
I think you should use response.body, and it should have been serialized.
A request body to be sent in the request. Cypress sets the Accepts request header and serializes the response body by the encoding option. (https://docs.cypress.io/api/commands/request#Usage)

How to send multiple post request using jmeter and json array?

I have this path in jmeter:
ctn_v2/wr/?${sid}&${pid}&f&${messageNumber}&${streamId}&${streamMessageId}&${dataFlagType}&subsid=${subsId}
what I want to do is to send multiple post request with different parameters using HTTP request with Jmeter.
I am taking the parameters from JSON file which contain JSON array which each item in the JSON array has values which I want to send in a different post request.
I used JSON path extractor to extract the values as follows (taken from DEBUG post sampler):
messageNumber_0=[0,1,2,4,3,5,6,7,8]
messageNumber_1=0
messageNumber_2=1
messageNumber_3=2
messageNumber_4=4
messageNumber_5=3
messageNumber_6=5
messageNumber_7=6
messageNumber_8=7
messageNumber_9=8
messageNumber_matchNr=9
msgSize=10
pid=2
protocol=https
sid=1600385571504156
streamId=[0,1,1,0,0,0,0,0,0]
streamId_1=0
streamId_2=1
streamId_3=1
streamId_4=0
streamId_5=0
streamId_6=0
streamId_7=0
streamId_8=0
streamId_9=0
streamId_matchNr=9
streamMessageId=[0,0,1,2,1,3,4,5,6]
streamMessageId_1=0
streamMessageId_2=0
streamMessageId_3=1
streamMessageId_4=2
streamMessageId_5=1
streamMessageId_6=3
streamMessageId_7=4
streamMessageId_8=5
streamMessageId_9=6
I want to be able to send the 1st post request with messageNUmber_0, streamId_0, etc... I tried to use 'counter' to resolve it but it didn't work out.
You can organize your Test Plan as follows:
While Controller: condition ${__javaScript(${counter} < ${messageNumber_matchNr},)}
Counter: starting value 1, Increment 1, Reference Name: counter
HTTP Request
In the HTTP Request sampler you can refer respective item names as:
${__V(messageNumber_${counter})}
${__V(streamId_${counter})}
and ${__V(streamMessageId_${counter})}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables

Send a queryset of models from Django to React using Ajax

I've been looking for info about this for hours without any result. I am rendering a page using React, and I would like it to display a list of Django models. I am trying to use ajax to fetch the list of models but without any success.
I am not sure I understand the concept behind JSon, because when I use the following code in my view:
data = list(my_query_set.values_list('categories', 'content'))
return JsonResponse(json.dumps(data, cls=DjangoJSONEncoder), safe=False)
It seems to only return a string that I cannot map (React says that map is not a function when I call it on the returned object). I thought map was meant to go through a JSon object and that json.dumps was suppose to create one...
Returned JSon "object" (which I believe to just be a string):
For the time being I have only one test model with no category and the content "At least one note "
[[null, "At least one note "]]
React code:
$.ajax({
type:"POST",
url: "",
data: data,
success: function (xhr, ajaxOptions, thrownError) {
var mapped = xhr.map(function(note){
return(
<p>
{note.categories}
{note.content}
</p>
)
})
_this.setState({notes: mapped})
},
error: function (xhr, ajaxOptions, thrownError) {
alert("failed");
}
});
Can someone please point me to the best way to send Models from Django to React, so I can use the data from this model in my front end?
I recommend using the Django REST Framework to connect Django to your React front-end. The usage pattern for DRF is:
Define serializers for your models. These define what fields are included in the JSONified objects you will send to the front-end. In your case you might specify the fields 'categories' and 'content.'
Create an API endpoint. This is the URL you will issue requests to from React to access objects/models.
From React, issue a GET request to retrieve a (possibly filtered) set of objects. You can also set up other endpoints to modify or create objects when receiving POST requests from your React front-end.
In the success function of your GET request, you will receive an Array of Objects with the fields you set in your serializer. In your example case, you would receive an Array of length 1 containing an object with fields 'categories' and 'content.' So xhr[0].content would have the value "At least one note ".
In your code, the call to json.dumps within the JsonResponse function is redundant. Check out the docs for an example of serializing a list using JsonResponse. If you are serializing the object manually (which I don't recommend), I'd use a dictionary rather than a list -- something like {'categories': <value>, 'content' : <value>}. DRF will serialize objects for you like this, so the fields are easier to access and interpret on the front-end.