Tag Archives: json

How to query the production environment logstash report error parsing JSON

1. Some errors are reported in the production environment

The information is as follows:

2021-10-15T15:49:28,932][WARN ][logstash.filters.json    ][main][7e17a3dc7e2c6df08ed7012ca6bfe17e3277d05d745f2c5bf55d2b01b151e25b] Error parsing json {:source=>"message", :raw=>"查询用户详情接口", :exception=>#<LogStash::Json::ParserError: Invalid UTF-8 start byte 0x9f
 at [Source: (byte[])"Query user details interface"; line: 1, column: 3]>}
[2021-10-15T15:49:28,946][ERROR][logstash.outputs.elasticsearch][main][862f1cf74fcefb4312e0b0aa2e9fdf074e2e77c675e5c24e9b7a04d1054f1947] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"%{aName}-log_2021_10", :routing=>nil, :_type=>"_doc"}, #<LogStash::Event:0x6527baeb>], :response=>{"index"=>{"_index"=>"%{aName}-log_2021_10", "_type"=>"_doc", "_id"=>nil, "status"=>400, "error"=>{"type"=>"invalid_index_name_exception", "reason"=>"Invalid index name [%{aName}-log_2021_10], must be lowercase", "index_uuid"=>"_na_", "index"=>"%{aName}-log_2021_10"}}}}
[2021-10-15T15:49:29,446][WARN ][logstash.filters.json    ][main][52e7421840cd9e07ac4081f9b005972562be1954f89c4f4bc5e30c5c19ebae78] Error parsing json {:source=>"message", :raw=>"spAuthAttributes ==========> {\"chainCodes\":\"60d9acb97314488689b899f4495e0857,3d01cb64635b46d4955606e6b356af70,c3283b04c2ad48a09d770b5a96b96a4c,850ff333c6664138b38344a75545ce8e\",\"customLoginStyle\":\"default\",\"samlEntityID\":\"portal\",\"securityLevel\":\"1\",\"spCode\":\"portal\",\"spLocalLogoutUrl\":\"\",\"spName\":\"portal\",\"spOsType\":0,\"tokenValidPeriod\":36000,\"url\":\"https://i.gt.cn\",\"userAttr\":\"\"}", :exception=>#<LogStash::Json::ParserError: Unrecognized token 'spAuthAttributes': was expecting ('true', 'false' or 'null')
 at [Source: (byte[])"spAuthAttributes ==========> {"chainCodes":"60d9acb97314488689b899f4495e0857,3d01cb64635b46d4955606e6b356af70,c3283b04c2ad48a09d770b5a96b96a4c,850ff333c6664138b38344a75545ce8e","customLoginStyle":"default","samlEntityID":"portal","securityLevel":"1","spCode":"portal","spLocalLogoutUrl":"","spName":"portal","spOsType":0,"tokenValidPeriod":36000,"url":"https://i.gt.cn","userAttr":""}"; line: 1, column: 18]>}
[2021-10-15T15:49:29,447][WARN ][logstash.filters.json    ][main][52e7421840cd9e07ac4081f9b005972562be1954f89c4f4bc5e30c5c19ebae78] Error parsing json {:source=>"message", :raw=>"redis执行时间:{}1", :exception=>#<LogStash::Json::ParserError: Unrecognized token 'redis执行时间': was expecting ('true', 'false' or 'null')
 at [Source: (byte[])"redis execution time: {}1"; line: 1, column: 21]>}

2. Processing method
this is because the log is not printed as required during processing. We need to open a new logstash to print the abnormal log
the configuration is as follows:

[root@k8s-master1 conf.d]# more aName1.conf 
input{
    kafka{
           bootstrap_servers => "10.152.17.50:9092"
           group_id => "gt-scs-log-new"
           topics => "gt-scs-log"
           consumer_threads => 1
           decorate_events => true
           auto_offset_reset => "latest"
           type => "gt-scs"
    }
}
filter {
    if [type] == "gt-scs" {
      mutate { 
                add_field => { "types" => "%{type}"}
             }
      json {
                source => "message"
          }
      json {
                source => "message"
          }

    }
}
output { 
  if [tags] { 
        stdout {
                codec => "rubydebug"
        }
  }
}

3. Results

Uncaught SyntaxError: Unexpected token o in JSON at position 1 [How to Solve]

JSON.parse(str); Error prompted during method execution;

The solution is very simple. Just pay attention to the format of STR parameter, which must be in the standard JSON string format

var str = '[{"code": "name", "name": "name"},{"code": "name1", "name": "name1"}]';

If the str value is passed through the background, be sure to confirm whether the format is correct

[system]SyntaxError: Unexpected token u in JSON at position 0

It was another day when I was annoyed by the bug. The error reports were as follows:

annotated all the codes, debugged them one by one, and finally found the error location:

after consulting the data, I found that JSON. Parse() can only process JSON format. If no item is passed in, it is equivalent to processing null values, Therefore, you can make a judgment before processing:

there is no problem.

[Solved] ERROR Error: Cannot find module ‘vue-loader-v16/package.json‘

Error Message:
ERROR  Error: Cannot find module ‘vue-loader-v16/package.json’
Error: Cannot find module ‘vue-loader-v16/package.json’
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at api.chainWebpack.webpackConfig (D:\3\data\dashboard\node_modules\_@[email protected]@@vue\cli-service\lib\config\base.js:114:23)
at webpackChainFns.forEach.fn (D:\3\data\dashboard\node_modules\_@[email protected]@@vue\cli-service\lib\Service.js:236:40)
at Array.forEach (<anonymous>)
at Service.resolveChainableWebpackConfig (D:\3\data\dashboard\node_modules\_@[email protected]@@vue\cli-service\lib\Service.js:236:26)
at Service.resolveWebpackConfig (D:\3\data\dashboard\node_modules\_@[email protected]@@vue\cli-service\lib\Service.js:240:48)
at PluginAPI.resolveWebpackConfig (D:\3\data\dashboard\node_modules\_@[email protected]@@vue\cli-service\lib\PluginAPI.js:132:25)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] serve: `vue-cli-service serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\lenovo\AppData\Roaming\npm-cache\_logs\2021-09-22T07_50_43_187Z-debug.log
Solution: Execute the following commands:
cnpm i vue-loader-v16

Weibo API api Called Error: error:appkey not bind domain! error_code:10017/2/statuses/share.json

Error message:

weibo4j.model.WeiboException: 400:The request was invalid.  An accompanying error message will explain why. This is the status code will be returned during rate limiting.
 error:appkey not bind domain! error_code:10017/2/statuses/share.json
	at weibo4j.http.HttpClient.httpRequest(HttpClient.java:404)
	at weibo4j.http.HttpClient.post(HttpClient.java:293)
	at weibo4j.http.HttpClient.post(HttpClient.java:279)
	at weibo4j.Timeline.updateStatus(Timeline.java:953)
	at weibo4j.examples.timeline.UpdateStatus.main(UpdateStatus.java:15)

Reason: the security domain name is not configured. The configured security domain name is attached to the status parameter

Error: Comments are not permitted in JSON [How to Solve]

Error: Comments are not permitted in JSON

The error is as follows

In the package.json file, you want to remove the comments of this line of code and always display comments are not allowed in JSON

Solution:

Change the JSON configuration in the lower right corner to JSON with comments

I have solved it!!!

c# Newtonsoft.Json.JsonReaderException: ‘Error reading JArray from JsonReader. Path ‘‘, line 0

When the data queried by c# datatable is converted to JSON object, the following error is reported.

Newtonsoft.Json.JsonReaderException: 'Error reading JArray from JsonReader. Path '', line 0, position 0.

The reason for this problem is that the queried data set directly becomes a string, and then an error is reported when it is empty
solution: add judgment

		if (jsonStr.Length > 0)
                {
                    JArray jArray = JArray.Parse(jsonStr);
                    JProperty Data = new JProperty("Data", jArray);
                    ZzjDataObj.Add(Data);
                }
                else
                {
                    JArray jArray = new JArray();
                    JProperty Data = new JProperty("Data", jArray);
                    ZzjDataObj.Add(Data);
                }

[Solved] com.alibaba.fastjson.JSONException: syntax error, pos 1, json

When I was working on a company project today, I came across this error message: com.alibaba.fastjson.jsonexception: syntax error, POS 1, JSON

later, I located the key code line where the error was reported. The

location object is not empty, and data.getstring (key) is also valuable, but the value is null after two consecutive gets in the sheet, I can’t understand it.

Finally, it is found that this cell does not exist, so it is null after getting the row and column. After null, it continues to set and reports a null pointer error

Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0

Problem: an error occurs when the page receives the passed JSON object

Reference page:

let invite = {
				id:albumID,
				unionid,
				role
			}
wx.navigateTo({
		url: `/pages/web/web?id=${id}&isShared=1&invite=${JSON.stringify(invite)}`,
	});

Receive page printing parameters:

console.log('invite',this.invite);
//console.log('invite',JSON.parse(this.invite));//报错 SyntaxError: Unexpected token u in JSON at position 0

The result is

Solution:

When receiving JSON data, decodeuri () is used for decoding

let {id,role,unionid} = JSON.parse(decodeURI(this.invite));

Front end error: exceptionmessage: null [How to Solve]

When updating an interface written by others before debugging, the front end always reports an error, exceptionmessage: null, similar to this format

the Java code sends a put request, The parameter requires a class

this is the field to be transferred during swagger UI test

this is the field of this class in the database table

it is not difficult to find that there are more fields in the class than in the database table, The only fields in the SQL statement that need to be modified are these

so I changed all the parameters to be transmitted to the parameters required by the SQL statement. The test was successful


then go to the front end. The front end fields correspond to the fields of the SQL statement. Some fields have and some do not, The parameters required by SQL can be changed uniformly. There is an episode in the middle. The front-end field name is different from the back-end field name, and this error is also reported.

Summary:

Exceptionmessage: null is mostly due to the inconsistency between SQL fields and database table fields or the different definitions of front and rear field names