how to set json with comment in vscode? - json

I often use Vs code to open json files. sometimes there're some comments in my json files. in this case,there will be a lot of warnings.
So I click below button to change the format to "json with comment (jsonc)"
but when I open a JSON file next time, it will by default switch to JSON format (without comment)
How can I make 'jsonc' the default format of json file? so that I do not need to change it every time.
Thanks

You can set a file association between json files and jsonc language formatting.
In VS Code open Settings in JSON view by using the Command Pallet (Cmd + Shift + P) and enter Preferences: Open Settings (JSON). Next, add the following (or append to the existing files.associations object if it already exists):
"files.associations": {
"*.json": "jsonc"
}

Related

How can we tell Prettier to ignore a specific JSON file?

I am using VS Code and would like to exclude a specific json file data.json from being formatted by Prettier on save. Say it's in the root, then I create a file .prettierignore and add a line data.json (according to the docs).
This works fine with other types of files, but not with json files. In fact, even writing *.json will still format the json files.
There is a setting in VS Code
JSON > Format:Enable
Enable/disabled default JSON formatter
which is enabled. When I disabled it, however, no json file will be formatted on save. This is not what I want. I only want to exclude a specific json file. How can I achieve this?
I have already seen the related question 46409892.
I think your VS Code formatter is not Prettier by default for JSON (or maybe not your default formatter for all documents ?)
To define a formatter by default, according to Prettier doc, you have to set your VS Code settings file like this :
{
// For all files
"editor.defaultFormatter": "esbenp.prettier-vscode",
// For JSON specifically
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
Then, you can define ignored files in your .prettierignore using same syntax as .gitignore.

ADF Merge-Copying JSON files in Copy Data Activity creates error for Mapping Data Flow

I am trying to do some optimization in ADF. Setup is a third-party tool copies one JSON file per object to a BLOB storage container. These feed to a Mapping Data Flow. The individual files written by the third party tool work great. If I copy these files to a different BLOB folder using an Azure Copy Data activity, the MDF can no longer parse the files and gives an error: "JSON parsing error, unsupported encoding or multiline." I started this with a Merge Files, but outcome is same regardless of copy behavior I choose.
2ND EDIT: After another day's work, I have found that the Copy Activity Merge File from JSON to JSON definitely adds an EOL character to each single JSON object as it gets imported to the Merge file. I have also found that the MDF fails definitely with those EOL characters in the Merge file. If I remove all EOL characters from the Merge file, the same MDF will work. For me, this is a bug. The copy activity is adding a character that breaks the MDF. There seems to be a second issue in some of my data that doesn't fail as an individual file but does when concatenated that breaks the MDF when I try to pull all the files together, but I have tested the basic behavior on 1-5000 files and been able to repeat the fail/success tests.
I took the original file, and the copied file, ran them through all of sorts of test, what I eventually found when I dump into Notepad++:
Copied file:
{"CustomerMasterData":{"Customer":[{"ID":"123456","name":"Customer Name",}]}}\r\n
Original file:
{"CustomerMasterData":{"Customer":[{"ID":"123456","name":"Customer Name",}]}}\n
If I change the copied file from ending with \r\n to \n, the MDF can read the file again. What is going on here? And how do I change the file write behavior or the MDF settings so that I can concatenate or copy files without the CRLF?
EDIT: NEW INFORMATION -- It seems on further review like maybe the minification/whitespace removal is the culprit. If I download the file created by the ADF copy and format it using a JSON formatter, it works. Maybe the CRLF -> LF masked something else. I'm not sure what to do at this point, but its super frustrating.
Other possibly relevant information:
Both the source and sink JSON datasets are set to use UTF-8 (not default(UTF-8), although I tried that). Would a different encoding fix this?
I have tried remapping schemas, creating new data sets, creating new Mapping Data Flows, still get the same error.
EDITED for clarity based on comments:
In the case of a single JSON element in a file, I can get this to work -- data preview returns same success or failure as pipeline when run
In the case of multiple documents merged by ADF I get the below instead. It seems on further review like maybe the minification/whitespace removal is the culprit. If I download the file created by the ADF copy and format it using a JSON formatter, it works. Maybe the CRLF -> LF masked something else. I'm not sure what to do at this point, but its super frustrating.
Repro: Create any valid JSON as a single file, put it in blob storage, use it as a source in a mapping data flow, to do any sink operation. Create a second file with same schema, get them both to run in same flow using wildcard paths. Use a Copy Activity with Merge Files as the Sink Copy Activity and Array of Objects as the File pattern. Try to make your MDF use this new file. If it fails, download the file created by ADF, run it through a formatter (I have used both VS Code -> "Format Document" from standard VS Code JSON extension, and VS 2019 "Unminify" command) and reupload... It should work now.
don't know if you already solved the problem: I came across the exact same problem 3 days ago and after several tries I found a solution:
in the copy data activity under sink settings, use "set of objects" (instead of "array of objects") under File Pattern, so that the merged big JSON has the value of the original small JSON files written per line
in the MDF after setting up the wildcard paths with the *.json pattern, under JSON Settings select: Document per line as the Document form.
After that you should be good to go, as least it solved my problem. The automatic written CRLF in "array of objects" setting in the copy data activity should be a default setting and MSFT should provide the option to omit it in the settings in the future.
According to my test:
1.copy data activity can't change unix(LF) to windows(CRLF).
2.MDF can also parse unix(LF) file and windows(CRLF) file.
Maybe there is something else wrong.
By the way,I see there is a comma after "name":"Customer Name" in your Original file,I delete it before my test.

Is it possible to have JSON schema autocomplete and documentation with eclipse?

I have a massive JSON setup file that I use with one of my projects. I would like to write some documentation and validation rules via a JSON schema so the edition of this file is easier for someone who's not familiar with it.
I want to be able to open the json setup file in Eclipse and have autocomplete for the json properties via intellisense. I also want to see the documentation comments for any json setup property when the mouse is over it.
I can't find any kind of documentation about this feature. Is this possible with eclipse?
I will answer my own question, cause I found the way to do it pretty easy and works quite well.
So,
· Having a test.json file which contains the setup of your project which
you want to get autocomplete features on
· Having a c:\test.schema.json file which contains the schema for your
setup file
The steps to activate this feature on eclipse are:
1- Open eclipse
2- go to "Window > Preferences: JSON > JSON Catalog"
3- add a new entry with "test.json" as the file and
"file:/c:/test.schema.json" as the URL
4- enable syntax and schema validation under "Window > Preferences:
JSON > JSON Files > Validation"
5- Apply the changes
6- Open the test.json file with eclipse and check that ctrl + space performs autocomplete
The only tedious part of this process that I've found is that every time the json schema file gets modified, you have to go again to "Window > Preferences: JSON > JSON Catalog" and apply the changes again to refresh the new values

Need to convert html to google doc native format using Java

I've read through the API documentation at https://developers.google.com/drive/v2/reference/ however I cannot find the answer to my question. And attempts to google a solution have failed.
I have a series of previously uploaded small HTML files sitting in Google Drive. What I want to do is write a short application to convert each of these to native Google Document format (mime type "application/vnd.google-apps.document").
I want to do this using Java code and not using GAS code.
The approach I used was to query drive for the File object corresponding to the item I want to convert. Then I pull that file's content as a string. Then I create a new file of mime type "application/vnd.google-apps.document" and upload it with the HTML content. Not surprisingly it didn't work.
So then I tried a different approach: Upload the content as "text/html" but set the "convert" flag to "true". Well I didn't see any direct API to set the convert flag to true. So I tried:
File oBody = new File() ;
oBody.setTitle ( sTitle ) ;
oBody.setDescription ( sDescription ) ;
oBody.setMimeType ( sMimeType ) ;
oBody.set("convert", bConvert);
This did not fail. But it did not create a Google Document either. It just created a text file identical to the original file.
How do I upload a document containing "text/html" content and get Google Drive to convert it automatically to a Google Document?
The convert flag has to be set in the files.insert request and not the File resource.
Using the snippet in the files.insert documentation as reference, this is what you should do:
...
File file = service.files().insert(body, mediaContent).setConvert(true).execute();
...

change file extention of JSON file in struts 2

My application has a mechanism in exporting and importing a json file. Exporting will happen after clicking a link. The exported file have a default ".action" extension since the link is mapped to an action.
How to change the file extension automatically to ".json" since importing requires ".json" extension?
Im using this result type
<result-type name="json" class="com.googlecode.jsonplugin.JSONResult" />
Normally you submit a form and the values are mapped onto the object, when using the json plugin you return a json string for ajax use... if you are really sending a file or returning a file then the content of the file has little to do with the issue.
See here for downloading a file with struts2: File download using Java, Struts 2 and AJAX