JSONpath fields with same name - json

I'm trying to get the user id's from twitter response (asking for several users)
https://dev.twitter.com/docs/api/1/get/users/lookup
But if i try
$.[*].id OR $..id
all fields with id (even nested fields) are retrieved.
How can i get the "id" field placed at first level?

I believe you would only get the first-level id's with the following query $[*].id. I believe this is what you were asking for; let me know if I misunderstood you.

Related

What is the URL when I DELETE an object

I'm running a local server playing around with an API using Django. I have a model called 'Users' populated with a few objects, and am using DefaultRouter.
I want to know what the URL would be if I were to DELETE a specific object from this model. For example, if I wanted to GET a user with an ID of 1 in this model, the URL would be: "localhost:8000/Users/1/". What would the equivalent be to DELETE this user?
I found an explanation of this on the REST API website (below), however, I don't understand what any of the syntaxes means.
What is {prefix}, {url_path}, {lookup} and [.format]? If anyone could provide an example of what this might be using a localhost that would be really helpful.
Thanks
Let us take an example of an API (URL) to update book data with id (pk) being 10. It would look something like this:
URL: http://www.example.com/api/v1/book/10/
Method: PUT/PATCH
With some data associated.
If you want to delete you just need to change method to DELETE instead of put or patch.
Regarding your second question lets compare the url with the parameters.
prefix: http://www.example.com/api/v1/book
lookup: 10
format: It specifies what type of data do you expect when you hit the API. Generally it is considered to be json.
url_path: In general, every thing after look up except query string is considered to be url_path.

Get array of friend names with friend id's from MongoDB

I'm making MEAN app for the first time. I managed to insert users into MongoDB. Each user looks like:
{
"name":"My Name",
"country":"Italy",
"friends":"5922c66b4e708e27a02b7937"
}
My first question is, how to manualy insert more than one friend (how to separate them via Postman)?
Then I have html page to show those informations about user, so I display his friends that way:
<td>{{user.userFriends}}</td>
When I will have more than one firend in database, how to display number of friends instead of their IDs?
Thanks for help!
EDIT: Solved the first part with
{
"friends":["5922c66b4e708e27a02b7937","5922c66b4e708e27a02b7938"]
}
To get Mongo to calculate the number of friends a user has, you can use the $size operator on the friends array. You need to use the aggregation pipeline to do this though. Otherwise, you can just calculate the length of the array yourself. For more details on the $size operator and the aggregation pipeline, see here: https://docs.mongodb.com/manual/reference/operator/aggregation/size/

having a bit of trouble trying to match fields and add fields to the matched ones

So ive been busting my brain for weeks. so id like to know that in MongoDB i have a table, so in this table there are multiple json objects, all objects have the same fields in, so what im trying to achieve is: match all doctuments by a specific set of ids eg "id": "1234" id like to match a specific fiel in all json objects and then add in another field just for those who match the search.. any ideas?
Although I am not fully clear about your question, but from whatever I understood,you can use $aggregate to solve your problem.
Refer to the below link->
https://docs.mongodb.com/v3.2/reference/method/db.collection.aggregate/

Google place api search result with place_id returns different location with place_id

I'm using google places api, but it returns the value with different place_id.
I have considered this blog : https://developers.google.com/places/documentation/search
I have requested with place id like this :
https://maps.googleapis.com/maps/api/place/details/json?key=AAIS...
In this url, you can see that the place_id is "EiJ..."
But in the returning json, i have received different place_id.
"place_id" : "AASS...",
"reference" : "df..."
When I have tried with reference, it was the same.
What did I wrong?
Is this the same location with different place_id?
Thanks for your help...
1) Never post your API key on a public forum. Go get yourself a new one.
2) reference has been deprecated, so you don't need to include it
3) EiJG... doesn't look like a Placeid. My guess is that you are trying to look up a value that doesn't exist and you're getting strange behavior.
Run a Place Search and get the Placeid and try again. You haven't posted what you searched for initially so it's impossible to verify that EiJ... really is a valid Placeid.
You can also have more than one place ID associated with a particular place.
In that case, if you request details using one place ID, you can get another ID back (you used the alternate ID, it returns what it considers the primary).
I found your question how to deal with this because I'll be storing information using their primary key and if it changes it will cause issues since the ID initially comes from their search (I'll get the new ID and not realize it is associated with the information I stored).

Restkit: Post an array of id's instead of the complete objects

I have a case where I need to post and array of numbers to the server side. E.g:
I have an order that have a list of products with one to many relation ships.
The question is how to post only array of id's for current order:
Now I have such result:
{"orders":[{"id":0,"Products":[{"productId":6},{"productId":7},{"productId":5},{"productId":3}]},{"id":1,.....]}
But I want to make it
{"orders":[{"id":0,"Products":[6,7,5,3]},{"id":1,.....]}
Any ideas ?
Update 1
I think I have found a solution
I have add method that fetch id's of my order products it's look like this
-(NSArray *)productsIds {
return [self.products.array valueForKeyPath:ProductAttributes.productId];
}
and add such a thing to my mapping code part.
[orderSerializationMapping addAttributeMappingsFromDictionary:#{#"productsIds" : #"Products"}];
And now result is
{"orders":[{"id":5,"Products":[17,13,16,11,12,19]},......]
You don't need add a method to fetch the id's. Setup your mapping like this:
[orderSerializationMapping addAttributeMappingsFromDictionary:#{#"products.productID": #"Products"}];