I have created a servlet with method post. Then, i used postman to request it with the JSON file in body. Now i want to create node with JSON that i retrieved from servlet. How can i do that? I know how to create node and setProperties but only String. I want to create node and setProperties with the JSON file like that
[
{
"_id": "5fc9dadaca52c28bb40011ee",
"index": 0,
"tags": [
"laboris",
"minim",
]
},
{
"_id": "5fc9dada30930ef9d77c6d91",
"index": 1,
"tags": [
"duis",
"est",
]
},
]
Please help me!
The Sling Post Servlet is what you're looking for. The import operation specifically:
https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#importing-content-structures-1
However, you need your JSON structure to be value pairs in the case of objects. Here's an example based on your sample json:
From the Front End
Here's an example calling the sling post servlet with a json file. You can follow the same pattern in JS but specifying
:content
instead of:contentFile
From the Back End
You can also create a POST request from the back end: