Skip to Main Content

how to add data in JSON file using REST API

Idris Patel-OracleDec 24 2020 — edited Dec 25 2020

Hello sir,
I try to add value in json file using REST API.
demo.js
var urlEndPoints = "json/end_points.json";
var nextKey = 2;
self.buildModel = function () {
return {
'id': self.inputID(),
'OS_Version' : self.select_Linux_OS_Version()
};
};
self.create = function (event) {
if (self.inputID(nextKey) < nextKey) {
self.inputID(nextKey);
}
nextKey += 1;
self.inputID(nextKey);
self.Collection.create(self.buildModel(), {
wait:true,
contentType : 'application/json',
success: function (model, response) {
console.log(self.inputID() + 'New record Add successfully');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(self.inputEmployeeID() + " -- " + jqXHR);
}
});
};
self.url = JSON.parse(urlEndPoints).os;
end_points.json
{
"os": "http://localhost:3000/os"
}
os.json
{
"os" : [
{
"id" : 1,
"OS_Version" : "Oracle-Linux-7.9-2020.11.10-1"
},
{
}
]
}
I face this issue. I think it couldn't find ID from json file. Can you suggest me what else I have to do?
I refer this : https://github.com/geertjanw/ojet-training
Uncaught SyntaxError: Unexpected token h in JSON at position 0
at JSON.parse (<anonymous>)

Comments
Post Details
Added on Dec 24 2020
0 comments
37 views