I got two json objects that I need to do sorts of ORM operations, such as count
, filter
, all
Here is the first object comments:
in views.py
comments_response = requests.get('https://jsonplaceholder.typicode.com/comments')
comments_data = json.loads(comments_response.text)
so below is what print(comments_data)
looks like:
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
},
]
This is second json object: in views.py
posts_response = requests.get(
'https://jsonplaceholder.typicode.com/posts')
posts_data = json.loads(posts_response.text)
so below is what print(posts_data)
looks like:
[
{
"postId": 1,
"id": 1,
"name": "id labore ex et quam laborum",
"email": "Eliseo@gardner.biz",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
{
"postId": 1,
"id": 2,
"name": "quo vero reiciendis velit similique earum",
"email": "Jayne_Kuhic@sydney.com",
"body": "est natus enim nihil est dolore omnis voluptatem numquam\net omnis occaecati quod ullam at\nvoluptatem error expedita pariatur\nnihil sint nostrum voluptatem reiciendis et"
},
]
Is it possible to use django ORM to the json object? such as comments_data.objects.count('title')
or comments_posts.objects.all()
. Does serializer from DRF can assist in this kind of operations? Do I need to use any other frameworks just to convert the json into ORM-able objects.?
Note: I did search related topics/questions, but most of them have the JSON data from their own internal database of which they have their total access (meaning they can already do ORM from start). In my case, I just received json objects from the external API and it is not from my internal database or any database that I have access from.
Some questions Ive seen but not answering my question:
1.https://stackoverflow.com/questions/66223066/django-getting-values-from-postgres-json-field
2.https://stackoverflow.com/questions/10445176/how-to-write-a-query-to-get-find-value-in-a-json-field-in-django
3.https://stackoverflow.com/questions/36389871/django-jsonfield-filtering