I receive "ReferenceError: parse is not defined" when running the following line in Node V6.11.0 inside an express router.
router.post('/api/addComp', function(req,res) {
var tempData = JSON.parse('{"compName":"Bodhi\'s Test", "compStreet":"12312 Glendale Av", "compCity": "Los Angeles", "compZip":"90039"}');
.
.
.
}
This code tests in the browser console and should be a part of Node by default from my understanding.
The error "ReferenceError: parse is not defined" will never occur because the method parse of JSON do not exist. Since you are calling it as an function executing the error thrown would be "JSON.parse is not a function", case JSON was not instantiated it would throw "cannot call parse of undefined". Some where else in your code you have a call to parse alone, separated by a typo error, like a coma or maybe a semicolon. Usually this error will only be thrown by an undeclared variable in strict mode.
JSON.parse('{"compName":"Bodhi\'s Test", "compStreet":"12312 Glendale Av", "compCity": "Los Angeles", "compZip":"90039"}'); was working as expected. Later lines of code had incorrect syntax for parseInt()
Related
how to check only one value is accepted when the request is inserted? if both values are passes then send the error message using json. Either RegNumber or Pan should be accepted. i am very new to this
{
"email_id": "sample#example.com",
"RegNumber": "AM47",
"FromDate": 062020,
"ToDate": 062022,
"SchemaCode": 560043,
"PAN": "ABC44X"
}
I think you meant by get error in json response means app should return Json when it crashes, so to do, we must use middlewares and when you expect some error in response override that response error with your own custom json dict with error details.
I am dealing with json circular reference object in angular7 so I used flatted package to resolve this but still not am getting following errors
ERROR TypeError: toISOString is not a function
also seeing warning like '[Deprecation] 'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.' from flatted/esm/index.js. am using flatted 2.0.0 version.
I tried with safe-json-stringify but it throws out of memory exception and chrome got stuck.
import { parse, stringify } from 'flatted/esm';
const objectTemp = {
'ConfigData': stringify(this.getData())
};
This.GetData() will have json circular reference object. How to stringify the json circular object.. am I missing anything here or is there any other way ?. Would be great if anyone can help me on this.?. Thanks
I'm using postman to validate the schema of json data returned from an api.
I have a test that runs through basic http validation, then ends with:
if (tv4.error){
console.log("Validation failed: ", tv4.error);
}
The error I get back is difficult to fathom.
Validation failed: 12:22:41.316
Object:{}
message:"Invalid type:
number (expected string)"
name:"ValidationError"
type:"Error"
But I need to know which field the validation failed on. How can I get this info? The npm page for tv4 suggests that the error message should be more descriptive.
According to the documentation of tv4, you can print the path of the error location using console.log(tv4.error.dataPath), I have no idea why this attribute is not logged in the console.
Documentation is here.
The relevant section in the documentation is:
If validation returns false, then an explanation of why validation failed can be found in tv4.error.
The error object will look something like:
{
"code": 0,
"message": "Invalid type: string",
"dataPath": "/intKey",
"schemaPath": "/properties/intKey/type"
}
I'm using the connect-redis-crypto module (https://github.com/jas-/connect-redis-crypto
) which is built for encrypting redis session data on top of connect-redis(https://github.com/tj/connect-redis). My redis version is 3.2.8.
I am running into error node-redis: Deprecated: The SET command contains a argument of type Object. Based on the larger error message, it seems to come from trying to parse the string [object Object] when it is not a JSON string. I put nested objects that hold user information on req.session which directly gets stored (and ideally encrypted) in redis.
From some sources I learned nested objects in Redis are not allowed which might cause this error, but I believe this library stores data as JSON to allow for nested objects. connect-redis works fine for me, but when this connect-redis-crypto library tries to JSON parse encrypted data it throws me this particular error.
Would really appreciate your help!
node_redis: Deprecated: The SET command contains a argument of type Object.
This is converted to "[object Object]" by using .toString() now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.
8 May 18:24:48 - ---NEW REQUEST---
REQUEST : GET /api/somePath/client
QUERY : {}
BODY : {}
data [object Object]
err SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at Command.callback (/Users/Documents/web-AOT/server/node_modules/connect-redis-crypto/lib/connect-redis.js:262:35)
at normal_reply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:721:21)
at RedisClient.return_reply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:819:9)
at JavascriptRedisParser.returnReply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:192:18)
at JavascriptRedisParser.execute (/Users/Documents/web-AOT/server/node_modules/redis-parser/lib/parser.js:560:12)
at Socket.<anonymous> (/Users/Documents/web-AOT/server/node_modules/redis/index.js:274:27)
at emitOne (events.js:96:13)
at Socket.emit (events.js:189:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:551:20)
The solution is here
You have to wrap your object in JSON.stringify and then remember to JSON.parse the response when you query the key later.
// set
client.set(
"key",
JSON.stringify(
{
example: {
field: "testing",
field1: 333
},
field: 123
}, () => {}
)
);
// get
client.get("key", (err, data) => {
console.log(JSON.parse(data));
});
Actually I was able to fix the error by making tweaks via the forked library. :)
If anyone ever runs into this error...
https://github.com/rjlee7/connect-redis-crypto
I am getting an error while sending a json object to server. My json object is as follows:
{
"AppVersion": "2.0",
"connection": "3G",
"received": "2015-10-30",
"smsContent": "test string",
"msisdn": "923453334444"
}
When I send request, I am getting this error:
Malformed JSON: Unexpected 'c'
What is wrong with my json object? Can someone help here?
This may be due to the incorrect syntax of your code. I also got this error and corrected by eliminating unnecessary semicolons from my code.