I am working on the typescript and mysql rest api, here i am storing
data as json in database i could do inserted api but i couldn't
updated which i stored as json , here i have attached my api.
const updateFooterGeneral = async (componentId: string, data: any) => {
const connection = await createConnection()
console.log(data)
try {
await connection.beginTransaction()
let sqlQuery = `UPDATE component_localization SET json_content=?,updated_date=? WHERE component_id = ?`
let params = [data.jsonContent, moment().format(), componentId]
let component:any = await connection.execute(sqlQuery, params);
console.log(component)
return component;
} catch (error) {
await connection.rollback()
throw error
}
}
Below are my postman json data how i have given in postman,
{
"componentId": "50",
"updated_date":"2023-01-13 08:14:16",
"jsonContent": "{{column1: {“logo of channel”:”http://localhost:3004/public/uploads/companylogos/companyLogo-1671176064887.png",
“telephone number” : "+39 0471 155 1350”,“adress of company”:”Handwerkerzone 12,Kaltern,Südtiro”,“mail_address”:”nfo#karriere-suedtirol.com”},column2:{“for candidates”:”Für Kandidaten”,value1:{“All jobs”:”Alle Jobs”,“link”:”http://localhost:3003/#”},value2:{“Companies”:”Firmen”,“link”:”http://localhost:3003/#” },value3:{“Talent coaching”:”Tolontberosune",
“link”:”http://localhost:3003/#"},
value4:{“Further education”:”Weiterbildung”,“link”:”http://localhost:3003/#”},value5:{“Career Hub”:”Karrier-Hub”,“link”:”http://localhost:3003/#”},column3:{“For employers”:”Für Arbeitgeber”,value1:{“Products & prices”:”Produkte & Preise”,“link”:”http://localhost:3003/#”},value2:{“Corporate benefit”:”Corporate Benefit”,“link”:”http://localhost:3003/#”},value3:{“My account”:”Mein Konto", “link”:”http://localhost:3003/#"}, value4:{“Support”:”Hilfebereich”,“link”:”http://localhost:3003/#”},value5:{“HR-HUB”:”HR-Hub”,“link”:”http://localhost:3003/#”},column4:{“About us”:”Über uns”,value1:{ “Team”:”Team”,“link”:”http://localhost:3003/#”},value2:{“Working for us”:”job bei uns,“link”:”http://localhost:3003/#”},value3:{“Partners”:”Partnerbereich",“link”:”http://localhost:3003/#"},value4:{“Support”:”Kontakt”,“link”:”http://localhost:3003/#”},value5:{“Contact”:”Hilfebereich”,“link”:”http://localhost:3003/#”},column5:{“Others”:”Sonstiges”,value1:{“Imprint”:”Impressum”,“link”:”http://localhost:3003/#”},value2:{“Terms & conditions”:”AGBs”,“link”:”http://localhost:3003/#”},value3:{“Privacy”:”Datenschutz",“link”:”http://localhost:3003/#" }, value4:{“Immo Südtirol”:”Immo südtirol”,“link”:”http://localhost:3003/#”},value5:{“Gastro Südtirol”:”Auto südtirol”,“link”:”http://localhost:3003/#”}}}"
}
If i hit this data in postman i am getting error like this ,
SyntaxError: Unexpected token " in JSON at position 4
at JSON.parse (<anonymous>) at
createStrictSyntaxError
(/Users/apple/Desktop/work1/clamsy/backend/node_modules/body-parser/lib/types/json.js:160:10)
at parse
(/Users/apple/Desktop/work1/clamsy/backend/node_modules/body-parser/lib/types/json.js:83:15)
at
/Users/apple/Desktop/work1/clamsy/backend/node_modules/body-parser/lib/read.js:128:18
at AsyncResource.runInAsyncScope
(node:async_hooks:203:9) at invokeCallback
(/Users/apple/Desktop/work1/clamsy/backend/node_modules/raw-body/index.js:231:16)
at done
(/Users/apple/Desktop/work1/clamsy/backend/node_modules/raw-body/index.js:220:7)
at IncomingMessage.onEnd
(/Users/apple/Desktop/work1/clamsy/backend/node_modules/raw-body/index.js:280:7)
at IncomingMessage.emit (node:events:513:28)
at endReadableNT (node:internal/streams/readable:1359:12)
jsoncontent is not valid string because of the misplaced quotes. try this
"jsonContent": "{{column1: {“logo of channel”:”http://localhost:3004/public/uploads/companylogos/companyLogo-1671176064887.png”,
“telephone number” : ”+39 0471 155 1350”,“adress of company”:”Handwerkerzone 12,Kaltern,Südtiro”,“mail_address”:”nfo#karriere-suedtirol.com”},column2:{“for candidates”:”Für Kandidaten”,value1:{“All jobs”:”Alle Jobs”,“link”:”http://localhost:3003/#”},value2:{“Companies”:”Firmen”,“link”:”http://localhost:3003/#” },value3:{“Talent coaching”:”Tolontberosune”,
“link”:”http://localhost:3003/#”},
value4:{“Further education”:”Weiterbildung”,“link”:”http://localhost:3003/#”},value5:{“Career Hub”:”Karrier-Hub”,“link”:”http://localhost:3003/#”},column3:{“For employers”:”Für Arbeitgeber”,value1:{“Products & prices”:”Produkte & Preise”,“link”:”http://localhost:3003/#”},value2:{“Corporate benefit”:”Corporate Benefit”,“link”:”http://localhost:3003/#”},value3:{“My account”:”Mein Konto”, “link”:”http://localhost:3003/#”}, value4:{“Support”:”Hilfebereich”,“link”:”http://localhost:3003/#”},value5:{“HR-HUB”:”HR-Hub”,“link”:”http://localhost:3003/#”},column4:{“About us”:”Über uns”,value1:{ “Team”:”Team”,“link”:”http://localhost:3003/#”},value2:{“Working for us”:”job bei uns,“link”:”http://localhost:3003/#”},value3:{“Partners”:”Partnerbereich”,“link”:”http://localhost:3003/#”},value4:{“Support”:”Kontakt”,“link”:”http://localhost:3003/#”},value5:{“Contact”:”Hilfebereich”,“link”:”http://localhost:3003/#”},column5:{“Others”:”Sonstiges”,value1:{“Imprint”:”Impressum”,“link”:”http://localhost:3003/#”},value2:{“Terms & conditions”:”AGBs”,“link”:”http://localhost:3003/#”},value3:{“Privacy”:”Datenschutz”,“link”:”http://localhost:3003/#” }, value4:{“Immo Südtirol”:”Immo südtirol”,“link”:”http://localhost:3003/#”},value5:{“Gastro Südtirol”:”Auto südtirol”,“link”:”http://localhost:3003/#”}}}
}"
Related
Flutter is giving me this error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: FormatException: Unexpected end of input (at character 88586)
[ ] E/flutter ( 5286): ...820457458, -0.09168463200330734, 0.9341723918914795, 0.9910492897033691]}",
This is how I am inflating the list (that is later written to a JSON file):
for(var i = 0 ; i <=32; ++i) {
String entry = '{contents: ['
'${contentList.content[i].x.toString()}, '
'${contentList.content[i].y.toString()}, '
'${contentList.content[i].z.toString()}, '
'${contentList.content[i].visibility.toString()}, '
'${contentList.content[i].presence.toString()}]}';
content_collector.add(entry);
}
content_collector is then passed to this function to write to a JSON file:
Future<File> saveToJSONFile(List<String> contents_list, String filename) async {
String encodedContents = jsonEncode(contents_list);
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path + '/' + filename;
return await File(appDocPath).writeAsString(encodedContents);
}
and I have this function to read the generated JSON file:
void readJSON(String path) async {
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path + '/' + path;
String response = await File(appDocPath).readAsString();
final data = await json.decode(response.toString());
}
So really, it is the readJSON function that throws this error.
This part is not valid JSON
{contents: [
it should be
{"contents": [
Most likely the other parts needs to be surrounded with " as well
As #julemand101 mentioned, this is not a proper approach, but also looking at the code, the string you are crating, is not being concatenated either. Try this:
String entry = "{'contents': [
'${contentList.content[i].x.toString()}',
'${contentList.content[i].y.toString()}',
'${contentList.content[i].z.toString()}',
'${contentList.content[i].visibility.toString()}',
'${contentList.content[i].presence.toString()}'
]}";
These are the responses
RESPONSE_1 = [fastfood:[[country:Canada,owner:[[name:John,totalEmployees:100,age:60],contractor:unknown]]]
RESPONSE_2 = [fastfood:[[country:Canada,owner:[[name:John,totalEmployees:100],[name:Mike,totalEmployees:80]],contractor:unknown]]]
Expected output in ${res1Diff}:
[age:60]
Expected output in ${res2Diff}:
[name:Mike,totalEmployees:80]
This is my 1st code, it returns null
stage('comparison') {
steps {
script {
if (RESPONSE_1 == RESPONSE_2) {
println("Matched")
} else {
println("Does not match")
def res1Diff = RESPONSE_1.minus(RESPONSE_2)
def res2Difd = RESPONSE_2.minus(RESPONSE_1)
echo "${res1Diff}"
echo "${res2Diff}"
}
}
}
}
Tried this one too, same it returns null (using .remove()) or error msg hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature method: .... (using .minus() or .removeAll())
RESPONSE_1.each { entry ->
def res2Diff = RESPONSE_2.minus("$entry")
}
echo "${res2Diff}"
I also tried this one, same output as the other
def res1 = res1.remove{entry ->
res2.contains("$entry.key:$entry.value")
}
echo "${res1Difference}"
How to compare and get differences of responses in Groovy?
RESPONSE_1 OUTPUT
{"entity":[{"employer1":[{"name":"John","age": 23}]}]}]}
RESPONSE_2 OUTPUT
{"entity":[{"employer1":[{"name":"John","age": 23}]}],"employer2":[{"name": "Mike","age": 26}]}]}
This one is my code. And it res1Differnce only returns null
stage('comparison') {
steps {
script {
if (RESPONSE_1 == RESPONSE_2) {
println("Matched")
} else {
println("Does not match")
def res1Difference = RESPONSE_1.minus(RESPONSE_2)
def res2Difference = RESPONSE_2.minus(RESPONSE_1)
echo "${res1Difference}"
echo "${res2Difference}"
}
}
}
}
I also tried to parse the RESPONSE_1 and RESPONSE_2 to map then used the .minus() and .remove() and .removeAll(). If .minus() or .removeAll() it returns hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature method: .... If .remove() it returns null.
def res1 = readJSON text: RESPONSE_1
def res2 = readJSON text: RESPONSE_2
res1.each { entry ->
def res2Difference = res2.minus("$entry")
}
echo "${res2Difference}"
I also tried this one, same output as the other
def res1 = res1.remove{entry ->
res2.contains("$entry.key:$entry.value")
}
echo "${res1Difference}"
Pls help me out how to return the differences of both responses.
This is the operation going on in my method
if (result) {
const csvdata = result.body;
var csvarray = csvdata.split('\n') //array details are shown below
for (var i = 1; i <= length; i++) {
const eachdata = csvarray[i];
var symbolarray = eachdata.split(",");
const obj = {
"instrument_token": symbolarray[0],
"exchange_token": symbolarray[1],
"tradingsymbol": symbolarray[2],
"name": symbolarray[3],
"last_price": symbolarray[4],
"expiry": symbolarray[5],
"strike": symbolarray[6],
"tick_size": symbolarray[7],
"lot_size": symbolarray[8],
"instrument_type": symbolarray[9],
"segment": symbolarray[10],
"exchange": symbolarray[11]
}
db.symboltable.create(obj)
.then((response) => {
console.log("added to symbol table")
})
.catch((err) => {
console.log(err)
})
}
csvarray contains elements like :
[
"267556358,1045142,EURINR20AUGFUT,\"EURINR\",0,2020-08-27,0,0.0025,1,FUT,BCD-FUT,BCD",
"268660998,1049457,EURINR20DECFUT,\"EURINR\",0,2020-12-29,0,0.0025,1,FUT,BCD-FUT,BCD",
"266440966,1040785,EURINR20JULFUT,\"EURINR\",0,2020-07-29,0,0.0025,1,FUT,BCD-FUT,BCD",
"266073606,1039350,EURINR20JUNFUT,\"EURINR\",0,2020-06-26,0,0.0025,1,FUT,BCD-FUT,BCD",
]
it contains thousands of similar elements and when the methods calls, i am getting an error like :
D:\MEAN\node projects\Trade\controllers\apicontroller.js:135
var symbolarray = eachdata.split(",");
^
TypeError: Cannot read property 'split' of undefined
at Request._callback (D:\MEAN\node projects\Trade\controllers\apicontroller.js:135:48)
at Request.self.callback (D:\MEAN\node projects\Trade\node_modules\postman-request\request.js:268:12)
at Request.emit (events.js:311:20)
at Request.<anonymous> (D:\MEAN\node projects\Trade\node_modules\postman-request\request.js:1489:10)
at Request.emit (events.js:311:20)
at IncomingMessage.<anonymous> (D:\MEAN\node projects\Trade\node_modules\postman-request\request.js:1360:12)
at Object.onceWrapper (events.js:417:28)
at IncomingMessage.emit (events.js:323:22)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
[nodemon] app crashed - waiting for file changes before starting...
can anyone get me out from this issue
Here is the code
loginController.prototype.newUserValidation = function(name,email,username,password, callback){
var errorMessage = {};
var name = validator.trim(name);
var email =validator.trim(email);
var username = validator.trim(username);
var password = validator.trim(password);
if(!validator.isLength(name,1)){
errorMessage.push("Name is required field");
}
if(!validator.isLength(email,1)){
errorMessage.push("Email is required field");
} else if(!validator.isEmail(email)){
errorMessage.push("Email is not valid");
}
if(!validator.isLength(username,1)){
errorMessage.push("username is required field");
}
if(!validator.isLength(password,1)){
errorMessage.push("password is required field");
}
callback(errorMessage);
}
This error is coming :
Object # has no method 'push'
TypeError: Object #<Object> has no method 'push'
at Database.loginController.newUserValidation (/home/vinove/Desktop/AshutoshJha/controller/login-controller.js:49:16)
at module.exports (/home/vinove/Desktop/AshutoshJha/routes/index.js:166:14)
at Layer.handle [as handle_request] (/home/vinove/Desktop/AshutoshJha/node_modules/express/lib/router/layer.js:95:5)
at next (/home/vinove/Desktop/AshutoshJha/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/vinove/Desktop/AshutoshJha/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/vinove/Desktop/AshutoshJha/node_modules/express/lib/router/layer.js:95:5)
at /home/vinove/Desktop/AshutoshJha/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/home/vinove/Desktop/AshutoshJha/node_modules/express/lib/router/index.js:330:12)
at next (/home/vinove/Desktop/AshutoshJha/node_modules/express/lib/router/index.js:271:10)
at Function.handle (/home/vinove/Desktop/AshutoshJha/node_modules/express/lib/router/index.js:176:3)
This is an object:
var errorMessage = {};
An object is a set of key/value pairs:
{
"name": "john",
"age" : 21
}
If you want to be able to add random data to your variable, you need an array:
var errorMessage = [];
Then your code would work
the push method is available for array datatype.
In your code you are defining json
i.e var errorMessage={}.
internally it is json.
Thats why it showing error Object # has no method 'push'
so too get rid of this error just change
var errorMessage = {};
to
var errorMessage = [];