VPavliashvili / json-nvim

Powerful Json processing capabilities in your Neovim buffer
MIT License
5 stars 0 forks source link

valid json found invalid #2

Open pierrekttipay opened 5 months ago

pierrekttipay commented 5 months ago

this json is detected as invalid by json-nvim though it is perfectly valid

{"message":"TypeError: Cannot access offset of type string on string in /Users/pierre/Documents/workspace/api/app/Http/Controllers/Api/RegisterController.php:71\nStack trace:\n#0 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\Api\\RegisterController->enroll(Object(App\\Http\\Requests\\EnrollRequest))\n#1 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\\Routing\\Controller->callAction('enroll', Array)\n#2 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\Api\\RegisterController), 'enroll')\n#3 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\\Routing\\Route->runController()\n#4 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): Illuminate\\Routing\\Route->run()\n#5 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#6 /Users/pierre/Documents/workspace/api/app/Http/Middleware/CheckForMaintenanceMode.php(25): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#7 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#8 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#9 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#10 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(159): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#11 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(135): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequest(Object(Illuminate\\Http\\Request), Object(Closure), Array)\n#12 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(87): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequestUsingNamedLimiter(Object(Illuminate\\Http\\Request), Object(Closure), 'api', Object(Closure))\n#13 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'api')\n#14 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#15 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(807): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))\n#16 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(784): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))\n#17 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(748): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))\n#18 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(737): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))\n#19 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))\n#20 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))\n#21 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#22 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#23 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#24 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#25 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#26 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#27 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#28 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#29 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(99): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#30 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#31 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(62): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#32 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#33 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#34 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#35 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#36 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))\n#37 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))\n#38 /Users/pierre/Documents/workspace/api/public/index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))\n#39 /Users/pierre/Documents/workspace/api/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php(16): require_once('/Users/pierreca...')\n#40 {main}","context":{},"level":400,"level_name":"ERROR","channel":"local","datetime":"2024-06-01T22:37:39.018322+10:00","extra":{}}
VPavliashvili commented 5 months ago

I tested it and it's working as intended, if you set filetype to json. Can you elaborate about the issue? what is the exact error?

pierrekttipay commented 5 months ago

Weird. I am on a .json file, I do :set filetype=json just to be sure.

I press Shift-V to select the entire line with the json I shared before. Then press : the prompt is autocompleting with:

:'<,'>

I delete and change it to :JsonFormatSelection getting: marked text is not a valid json

pierrekttipay commented 5 months ago

On that same line, I tried :JsonFormatToken instead just to test a little.

jq: parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 43, column 11
VPavliashvili commented 5 months ago

Unfortunately I cannot reproduce your issue, I tested on separate Linux and Windows environments and both worked as intended(formatted as collapsed your given json with various commands).

Can you try and run :JsonFormatFile on your original json code inside the new buffer? Or just save it into a file and run jq on that file. if it still returns the error then problem is between your json and jq

pierrekttipay commented 5 months ago

I am on mac. that could be the issue: running :JsonFormatFile rewrite the entire file with

jq: parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 43, column 11

running cat ./storage/logs/laravel.json | jq on that file (outside of nvim) works well. The output is formatted by jq without error.

VPavliashvili commented 5 months ago

I think this issue will be solved if target json will be saved into file at first and then send it into jq. All operations on windows are implemented similarly. Unfortunately I don't have any access on mac and won't be able to test the behaviour tho