VSCode: File is too large for tokenization / formatting
Asked Answered
R

3

13

I have an 800kb *.json file all condensed into one line.

The built-in JSON formatter seems to refuse to format and tokenize the file and after searching for a while I haven't found any solutions. How can I do this?

Regarding answered 10/12, 2019 at 9:51 Comment(1)
according to this issue there's a 20k char limit for that functionality to workMeshwork
V
25

I needed to format ~90MB json file. Initially Vscode was stubborn, but I found a workaround.

Open JSON file and 'save as' it under any name. Somehow this triggers something and it then becomes recognised as JSON file. Then you can use 'Format Document'.

Beawere, first time it crashed Vscode because process was suspended. Had to close and start over, just this time I set the priority on Vscode process to high and then it ran fast and quite smoothly.

My PC has 24GB ram, Vscode was using about 7.

Veinule answered 3/2, 2022 at 19:15 Comment(1)
Did not work on 1.84.0, on a macOS 12.7Posterity
T
3

First, you need to have JSON extension installed in VS Code.

You need to increase the maximum number of outline symbols and folding regions computed.

Go to Settings -> input json.maxItemsComputed in the search bar -> increase the number from 5000 to any number you need.

enter image description here

Testaceous answered 8/3, 2023 at 12:44 Comment(0)
W
3

Based on another SO thread, you can use a simple python command to format large JSON files

cat ugly.json | python -m json.tool > pretty.json
Worm answered 26/2 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.