Cannot display JSON file created and saved in Visual Studio Code - json

When I create a file in Visual Studio Code (on a Windows 7 box), add some content, then save it, the content is replaced with the following message:
The file cannot be displayed in the editor because it is either binary
or uses an unsupported text encoding.
My workaround is to create and save the file in Sublime Text, then I can open it, edit it, and save it in VS Code.
What do I need to do to get the file to save with the proper encoding?
Here are the steps I'm taking:
Create a new file in VS Code
Set the language of the file to JSON (bottom-right of editor)
Enter the following
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
Save the file as test.json

This is a bug in VS Code that has been fixed and will be available in the next update. Sorry for that! It does not happen for all file types, but for JSON unfortunately.
Update
Meanwhile new versions have been released that fix the issue.

This is a bug in VS Code. If you are running into it, rather than setting the language of the file, save the file with the .json extension, and VS Code will detect the language and correctly display the file.
I've submitted the bug here:
https://code.visualstudio.com/issues/detail/16781

Related

Pushing an empty file instead of another to github

I have a local repository with a config.json file which contains sensible configuration data. This file follows a schema found in config.json.template. The two files look like these (not actual content):
config.json.template
{
"username": "",
"password": "",
}
config.json
{
"username": "admin",
"password": "123456789"
}
Instead of placing the config.json in my .gitignore, is there a way to replace it with config.json.template at push-time? So that my repository will contain a config.json file that just needs to be filled out by the user.
You're better off pushing just the template file and not a file that you want people to modify. People working with your repository won't appreciate having a tracked file that they must modify, since it means that git checkout and other operations will sometimes require them to stash first and then unstash.
In general, files that are intended to be modified on a per-user basis, like configuration files or editor files, shouldn't be saved directly in version control.
You can just simply push config.json.template as it is.

Jupyter opens .ipynb as plain text instead of showing interactive cells

My laptop was shut down when it ran out of battery while I was editing the ipnyb file in the Jupyter notebook, now when I am trying to open my ipnyb file in jupyter notebook (anaconda setup), the file is shown as plain text instead of interactive cells.
The file content as shown below: { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### This is a file python file'\n", "\n", .................
Is there any way to open the ipnyb file back in the interactive cell mode?

How can I convert a .txt file into a JavaScript object?

I am just out of bootcamp and not familiar with .jl files. I read a solution on stack overflow to convert the .jl files into .txt and the files look like JSON syntax - but I am not experienced enough to say it absolutely is JSON!
The .txt file looks like this - if I wanted to access this file with FE React.js framework and only the product_id/ price / product_imgs_source - is there a method to do this? I can use the data simply by hard-coding it into an array and using it as front-end data and it works - but I am looking for a method that helps me map through this .txt data so a data-transformation method from .txt to .js
{"product_categories_mapped": [24]
"product_id": "ny221a00q-n11",
"price": "84.99",
"product_title": "some description",
"product_imgs_src": ["https://some.jpg"],
"images": [{"url": "https://some.jpg",
"path": "some.jpg",
"checksum": "10f6a0dc3db6b15724cebe9b1cb244be"}],
}
When I used the global fetch() method on the data that was a https link from aws s3 db with a .jl file extension - the error was a 403 so I converted the .jl files to a .txt file and would be great if I could use a JavaScript method to access the .txt data - my worst option is to make it work by manually extracting the data and hardcoding it into an array of objects and accessing the information in the front-end, then creating a node-express environment and a mongo-db collection from this data that I have manually extracted - if there is a better way I will be grateful for any suggestions!

What are the contents of the default brackets.json file?

I accidentally deleted my brackets.json file.
Could somebody with the Brackets Editor open it up, go to Debug, opens the settings file, and paste it into an answer?
Here is the file that Brackets generates for me:
{
"fonts.fontSize": "12px",
"fonts.fontFamily": "'SourceCodePro-Medium', MS ゴシック, 'MS Gothic', monospace",
"linting.collapsed": true,
"autoSavePrefs.on_save": false,
"dragDropText": true,
}
Unfortunately, this causes the following message to appear every time I start the editor:
your settings file doesn't contain a valid json file. The file will be opened so you can correct the format. You have to restart Brackets, so the changes affect brackets.
and I'm not sure how to fix it.
JSON doesn't permit trailing commas in object members or array elements.
If you change "dragDropText": true, to "dragDropText": true your file will become valid JSON and your error message should go away.
What I did and it worked was remove all references to the json file, leaving just {
}
It will create another default settings.

Convert .json to ipynb

I am taking a course that uses ipython notebook. When I try to download the notebook (through File -> Download as -> ipython notebook), I get a file that ends with ".ipynb.json". It doesn't open as an ipython notebook but as a .json file so something like this:
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"_You are currently looking at **version 1.1** of this notebook. To download notebooks and datafiles, as well as get help on Jupyter notebooks in the Coursera platform, visit the [Jupyter Notebook FAQ](https://www.coursera.org/learn/python-data-analysis/resources/0dhYG) course resource._\n",
"\n",
"---"
]
},
...
}
I've tried deleting the ".json" in the file name and it doesn't work. How can I convert this file back to something that can be opened and run as an ipython notebook? Thank you very much!
My Solution: just remove the filename extension .json. for example, change myfile.ipynb.json to myfile.ipynb. Then, you can open it by a click in jupyter notebook !
I have encounter the same problem as you did. I found a link that describe what ipynb exactly is. see here http://ipython.org/ipython-doc/rel-1.0.0/interactive/nbconvert.html. It says ipynb file is actually json file. Hope this
On the Mac you could go and
Right click on the filename.ipynb.json
Click on Get Info from the list.
From the Get Info window, find the section Name&Extension remove the extension/suffix .json from the file name.
Hope that helps!
Are you trying download this from Github? Especially on Google Chrome browsers, I've had issues download .ipynb files using right click > Save link as... I'm not sure if other browsers have this issue (Microsoft Edge, Mozilla Firefox, Safari, etc.).
This causes issues since when downloading, it doesn't completely download the file usually and it becomes corrupted so you can't download an IPython notebook that may run properly. One trick when trying to download .ipynb files on Github is to click it, click Raw, then copy everything (Ctrl + A) and paste it into a blank file (using text editors such as Notepad, Notepad++, Vim, etc.) and save it as "whatever_file_name_you_choose.ipynb". Then you should be able to properly run this file, assuming a non-corrupted file was uploaded to Github.
A lot of people with very large, complicated IPython notebooks on Github will inevitably run into this issue when simply trying to download with Save link as.... Hopefully this helps!
I opened it as/with nbviewer and then selected it all and saved it as a "txt" file that I then opened in Notepad++. I then resaved it as a file with the extension ipynb and opened it in my jupyter notebook ok.
The easy thing to do is to copy the JSON contents into a notepad and save it again with .ipynb extension
Just remove the .json file extension leaving the .ipynb one, as pointed out by the following related post: https://superuser.com/questions/1497243/why-cant-i-save-a-jupyter-notebook-as-a-ipynb. As #jackie already said, you should consider them as .json files meant only to be edited by the IPython Notebook app itself, not for hand-editing.
Use a simple trick. Let that file get downloaded automatically. Re-download it again then it will prompt you to download and replace that file. At that time, you save that by replacing .json to .ipynb
After downloading the file with ipynb.json, Take the following steps:
Go your terminal/command line window
Navigate to the directory where your file is
Type:
windows OS: rename yourfile.ipynb.json to yourfile.ipynb
Unix/Linux: mv yourfile.ipynb.json to yourfile.ipynb
This work perfectly for me.
i tried this method and it worked. Just copy, paste it in notepad and save as "file_name.ipynb". hope this works for you too.