npm unexpected token / in config.json at position 98 - json

I have seen several unexpected token errors related to npm but this one is yet again unique to me. I could not find any similar issues posted by others. My config file just has connection objects to my local mongodb, rabbitmq "amqp", wordpress plugin and mysql DB.
Could anyone help me with this error in case they've seen it before?
C:\xampp\htdocs\livetrader\chat\node_modules\nconf\lib\nconf\stores\file.js:160
throw new Error("Error parsing your configuration file: [" + this.file + ']: ' + ex.message);
^
Error: Error parsing your configuration file:
[C:\xampp\htdocs\livetrader\chat/config.json]: Unexpected token / in JSON at position 98
Updating this post with the config.json file referenced in this error
{
"port": 1337,
"mongoose": {
"uri": "mongodb://localhost:27017/livetrader"
},
"amqp":{
"uri": "amqp://guest:guest#localhost:15672",
"queue": "TickData"
},
"sql":{
"host":"localhost",
"database":"db_main",
"user":"root",
"password":""
},
"wp":{
"host":"http://forextrader.dev",
"LOGGED_IN_KEY":"MY_LOGGED_IN_KEY",
"LOGGED_IN_SALT":"MY_LOGGED_IN_SALT",
"prefix":"wp_",
"avatarPath":"http://localhost/livetrader/wp-content/uploads/avatars",
"myCreedApi":"MY_API_KEY"
},
"guest":{
"cookie_name": "trading-forex-guest",
"ttl": 180
}
}
Updating the back-end config path
"use strict";
var nconf = require('nconf');
nconf.argv()
.env()
.file({
file: process.cwd() + '/config.json'
});
module.exports = nconf;

Your JSON file is property formatted. JSON.parse() takes it, no problem. Character 98 is not a slash, either.
There is, however, a suspicious slash in your path:
C:\xampp\htdocs\livetrader\chat/config.json
The final slash is unix-style, not windows-style. Could that be causing the problem?
If that's not it, you must be reading the wrong file, or passing it the wrong way to a function. Try using console.log to figure out what exactly is reaching JSON.parse().
Giving objects to JSON.parse() can cause unexpected errors, since .toString() is invoked. For example:
> JSON.parse({a:1})
SyntaxError: Unexpected token o in JSON at position 1
> ({a:1}).toString()
'[object Object]'
So, to recap, you must be:
Reading the wrong file
Passing an object that's not a String to JSON.parse()
Having a strange problem with the inverted slash in the path

Related

Json data not get in terminal & get error->(SyntaxError: Unexpected end of JSON input)

I am trying to get some value from Youtube Api. Now, My express code is->
https.get("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=qW_SWM1wpMA&key=MYAPIKEY",function(res){
res.on("data",function(data){
const da=JSON.parse(data);
console.log(da);
})
});
Now, I am console log the data what's coming from api. But I get this error->
$ node app.js
Port is running
undefined:13
"description": "\"Bang Bhaja\" shows how Nonte and Fonte makes a trick to punish Keltu for punishing them from Superintendent Sir for eating the Ilish Maach.\n\nNonte Fonte is a Bengali comic-strip creation of Narayan Debnath which originally was serialized for the childre
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at IncomingMessage.<anonymous> (C:\Users\LENOVO\Desktop\youtube\app.js:13:19)
at IncomingMessage.emit (events.js:314:20)
at IncomingMessage.Readable.read (_stream_readable.js:514:10)
at flow (_stream_readable.js:987:34)
at resume_ (_stream_readable.js:968:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
But when paste the API link (what's mention in above in https.get method) in chrome I get the json data successfully. Then why not i getting the json data in terminal?

sails-mysql error handling : TypeError: Converting circular structure to JSON

Server: Sailsjs
Database: mysql
Node Library used: sails-mysql(0.11.5)
I am trying to insert a data in mysql from sailsjs node server.
Data to be inserted:
{
"first_name": "Admin Testing",
"last_name": "User",
"email": "admin14#testing.com",
"role_id": 8
}
Where role_id is having a foreign key relation to model role.
Here the role_id : 8 doesn't have value in role table. So while inserting, it is throwing the error. But that error we couldn't console or json.stringify since the following error occurs:
TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at /var/www/aitachatbot/server/api/controllers/UserController.js:38:42
at wrapper (/var/www/aitachatbot/server/node_modules/waterline/node_modules/lodash/index.js:3602:19)
at applyInOriginalCtx (/var/www/aitachatbot/server/node_modules/waterline/lib/waterline/utils/normalize.js:421:80)
at wrappedCallback (/var/www/aitachatbot/server/node_modules/waterline/lib/waterline/utils/normalize.js:331:16)
at error (/var/www/aitachatbot/server/node_modules/switchback/lib/normalize.js:42:31)
at _switch (/var/www/aitachatbot/server/node_modules/switchback/lib/factory.js:56:28)
at /var/www/aitachatbot/server/node_modules/sails-hook-validation/lib/create.js:66:21
at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/query/dql/create.js:223:14
at wrapper (/usr/local/lib/node_modules/sails/node_modules/lodash/index.js:3592:19)
at applyInOriginalCtx (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:421:80)
at wrappedCallback (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:335:16)
at error (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/normalize.js:42:31)
at _switch (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/factory.js:56:28)
at afterwards (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/adapter/dql.js:87:16)
at wrapper (/usr/local/lib/node_modules/sails/node_modules/lodash/index.js:3592:19)
at applyInOriginalCtx (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:421:80)
at wrappedCallback (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:335:16)
at error (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/normalize.js:42:31)
at _switch (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/factory.js:56:28)
at sendBackError (/var/www/aitachatbot/server/node_modules/sails-mysql/lib/connections/spawn.js:97:11)
at Object.poolfully [as releaseConnection] (/var/www/aitachatbot/server/node_modules/sails-mysql/lib/connections/release.js:28:12)
at /var/www/aitachatbot/server/node_modules/sails-mysql/lib/connections/spawn.js:90:37
at Query._callback (/var/www/aitachatbot/server/node_modules/sails-mysql/lib/adapter.js:395:27)
at Query.Sequence.end (/var/www/aitachatbot/server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Query.ErrorPacket (/var/www/aitachatbot/server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:94:8)
at Protocol._parsePacket (/var/www/aitachatbot/server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:280:23)
at Parser.write (/var/www/aitachatbot/server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:73:12)
How can we handle this error in sailsjs?
In theory, you don't want these errors to ever show up in production... even if they did, the full json dump of the error object probably is not something a run-of-the-mill user wants to see.
You may also be asking about how to get full info out of this error while debugging. I guess the good news there is, you seem to already know the root cause of your error!
The error objects we have in node can have pretty different structures depending where they come from, but I have yet to encounter an error that does not have smart casting of the errors to strings. That means that even if console.log(err) fails, something like: console.log('Got an error: ' + err) will likely work, casting the error to a string.
The code could be something like this:
User.create({
"first_name": "Admin Testing",
"last_name": "User",
"email": "admin14#testing.com",
"role_id": 8
}).exec(function(err, createdUser) {
if (err) {
var readableErr = '' + err;
console.log('Error creating user: ' + readableErr);
// return something the client will recognize and interpret
// you can use http error codes, or your own conventions
return res.send({
success: false,
message: readableErr
});
}
// do something with createdUser...
});

log4js configure function error [NodeJs]

I am getting the following error in console window when running my NodeJs application. I am using log4js for logging. Runtime platform is express.
Error:
undefined:1
?{
^
SyntaxError: Unexpected token ? in JSON at position 0
Code:
var log4js = require('log4js');
var mylog = log4js.configure('log4jsConfig.json');
logger = log4js.getLogger("absolute-logger");
Config json:
{
"appenders": [
{
"type": "file",
"absolute": true,
"filename": "c:/temp/log_file.log",
"maxLogSize": 20480,
"backups": 10,
"category": "absolute-logger"
}
]
}
Question:
Any thoughts. I am thinking this is parsing error, but not sure how to resolve it.
Thanks,
Are you on a windows system? Sometimes, parsers get upset with \r\n (carriage returns). Try converting it UNIX (new line only) style lines.

Missing exception info in NodeJS JSON.parse

In NodeJS, if I let a JSON.parse exception go unhandled and subsequently crash the server, I get an important bit of information outputted to the console.
My JSON:
{
"familyName": "The Flintstones",
"familyContact": {
"fullName": "Wifie Flintstone",
"contact": {
"street1": "1 Granite Ave",
"city": "Bedrock",
"state": "TX",
"postal": "10000"
}
},
this should make it blow up
"patients": [{
"personInfo": {
"fullName": "Wilma Flintstone"
}}, {
"personInfo": {
"fullName": "Fred Flintstone"
}
}
]
}
This is the console output when I let it go unhandled:
undefined:12
this should make it blow up
^
SyntaxError: Unexpected token t
at Object.parse (native)
at Object.exports.uploadPackage.flowUploads.post.flowUploads.write.onDone (/home/ubuntu/workspace/app/controllers/admin/admin.families.server.controller.js:99:27)
at module.exports.$.write.pipeChunk (/home/ubuntu/workspace/app/services/flowUploads.js:173:49)
at Object.cb [as oncomplete] (fs.js:169:19)
but if I catch the exception to prevent the crash, and log like so...
try{
var fileData = JSON.parse(fileText);
}
catch (ex) {
console.log("REASON FOR JSON FAILURE: " + ex, ex.arguments, ex.stack.split("\n"));
}
I get output like this:
REASON FOR JSON FAILURE: SyntaxError: Unexpected token t [ 't' ] [ 'SyntaxError: Unexpected token t',
' at Object.parse (native)',
' at Object.exports.uploadPackage.flowUploads.post.flowUploads.write.onDone (/home/ubuntu/workspace/app/controllers/admin/admin.families.server.controller.js:100:27)',
' at module.exports.$.write.pipeChunk (/home/ubuntu/workspace/app/services/flowUploads.js:173:49)',
' at Object.cb [as oncomplete] (fs.js:169:19)' ]
Missing that key piece of useful info from the crash log that contains the line number and snip of faulty text:
undefined:12
this should make it blow up
^
How I can get to that bit so I can include it in my error messaging?
You can't get that first bit you displayed from the error since it isn't part of the error.
undefined:12
this should make it blow up
^
This is because node is adding that section before dying to show why it died and then shows the error generated by JSON.parse.
To get more detailed messaging you will have to use something other then JSON.parse. As robertklep mentioned you could try greatjson or something similar if getting greater detail on your JSON parsing is important, such as if you are building a service which parses JSON and returns the errors.

Solr return 400(bad request) while indexing the json file from localhost

I am new in Solr . I have setup solr in local pc. I am facing problem with the indexing of json file. I have one json file in local pc which i want to index in solr. it show some error which i have mention below.
Error
D:\Solr\Example\exampledocs>java -Durl=http://localhost:8983/solr/update -Dtype=application/json -jar post.jar timeline.json
SimplePostTool version 1.5
Posting files to base url http://localhost:8983/solr/update using content-type application/json..
POSTing file timeline.json
SimplePostTool: WARNING: Solr returned an error #400 (Bad Request) for url: http://localhost:8983/solr/update
SimplePostTool: WARNING: Response: {"responseHeader":{"status":400,"QTime":0},"error":{"msg":"Unknown command: Name [8]","code":400}}
SimplePostTool: WARNING: IOException while reading response: java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:8983/solr/update
1 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/update..
Time spent: 0:00:00.167
Please help me , how can i solve it? Thanks in advance.
Log show
ERROR - 2014-07-30 18:38:52.330; org.apache.solr.common.SolrException; org.apache.solr.common.SolrException: Unexpected character '{' (code 123) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
at org.apache.solr.handler.loader.XMLLoader.load(XMLLoader.java:176)
at org.apache.solr.handler.UpdateRequestHandler$1.load(UpdateRequestHandler.java:92)
at org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:74)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1962)
at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:777)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:418)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:207)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:368)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:953)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1014)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:648)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2047)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)
at org.apache.solr.handler.loader.XMLLoader.processUpdate(XMLLoader.java:213)
at org.apache.solr.handler.loader.XMLLoader.load(XMLLoader.java:174)
... 32 more
Json file
{ "Name" : "Matches and Schedule", "timestamp" : { "$date" : 1400825267792 }, "_id" : { "$oid" : "537ee50494" } }
{ "Name" : "meet Modi", "timestamp" : { "$date" : 1401449841192 }, "_id" : { "$oid" : "53886d3a2c" } }
Can't comment yet.
Please post a snippet of your JSON file so we can comment.
Also, in these cases, Solr log files are your best friend, they will tell you exactly what it doesn't like about the data you are posting.
Also, you don't have to specify the host if you are sending to localhost, it is the default.
EDIT: Your JSON doesn't look correct. What do you expect it to do with stuff like:
"timestamp" : { "$date" : 1400825267792 }
First of, if you need timestamp is solr to be a date/time field it needs to be in UTC format. Second, Solr doesn't support nested elements.
Finally, if you are posting multiple documents via json, the format needs to look like this:
[ {"id":"doc1","field2":"val2"} , {"id":"doc2","field2":"val3"} ]
Note that all documents are enclosed in square brackets and separated by a comma.