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.
Related
I'm making my first videogame in Unity and I was messing around with storing data in JSON files. More specifically, language localization files. Each file stores key-value pairs of strings. Keys are grouped in categories (like "menu.pause.quit").
Now, since each language file is essentially going to have the same keys (but different values), it would be nice if VS code recognized and helped me write these keys with tooltips.
For example, if you open settings.json in VS code, if you try to write something, there's some kind of autocompletion going on:
How does that work?
The auto completion for json files is done with json schemas. It is described in the documentation:
https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings
Basically you need to create a json schema which describes your json file and you can map it to json files via your user or workspace settings:
// settings.json
{
// ... other settings
"json.schemas": [
{
"fileMatch": [
"/language-file.json"
],
"url": "./language-file-schema.json"
}
]
}
This will provide auto completion for language-file.json (or any other file matched by the pattern) based on language-file-schema.json(in your workspace folder, but you can also use absolute paths)
The elements of fileMatch may be patterns which will match against multiple files.
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"
}
I have noticed there is a feature in web interface of ArangoDB which allows users to Download or Upload data as JSON file. However, I find nothing similar for CSV exporting. How can an existing Arango DB collection be exported to a .csv file?
If you want to export data from ArangoDB to CSV, then you should use Arangoexport. It is included in the full packages as well as the client-only packages. You find it next to the arangod server executable.
Basic usage:
https://docs.arangodb.com/3.4/Manual/Programs/Arangoexport/Examples.html#export-csv
Also see the CSV example with AQL query:
https://docs.arangodb.com/3.4/Manual/Programs/Arangoexport/Examples.html#export-via-aql-query
Using an AQL query for a CSV export allows you to transform the data if desired, e.g. to concatenate an array to a string or unpack nested objects. If you don't do that, then the JSON serialization of arrays/objects will be exported (which may or may not be what you want).
The default Arango install includes the following file:
/usr/share/arangodb3/js/contrib/CSV_export/CSVexport.js
It includes this comment:
// This is a generic CSV exporter for collections.
//
// Usage: Run with arangosh like this:
// arangosh --javascript.execute <CollName> [ <Field1> <Field2> ... ]
Unfortunately, at least in my experience, that usage tip is incorrect. Arango team, if you are reading this, please correct the file or correct my understanding.
Here's how I got it to work:
arangosh --javascript.execute "/usr/share/arangodb3/js/contrib/CSV_export/CSVexport.js" "<CollectionName>"
Please specify a password:
Then it sends the CSV data to stdout. (If you with to send it to a file, you have to deal with the password prompt in some way.)
I am trying to install and configure the Atom Editor IDE using Ansible.
I know how to retrieve and parse a JSON file with Ansible, but I don't see how to insert/update some fields of that JSON file when seen as a dictionary, also dealing with the fact that the file may not be there at the beginning of the Ansible workbook.
I know the settings are stored in ~/.atom/config.cson.
My initial configuration looked like this:
$ cat ~/.atom/config.cson
"*":
core:
telemetryConsent: "limited"
editor:
invisibles: {}
"exception-reporting":
userId: "<SOME_UUID>"
But then I wanted to make sure tabs were treated as 2 blank spaces, so I went on the Settings window, changed some parameters and then the configuration file looked like:
$ cat ~/.atom/config.cson
"*":
core:
telemetryConsent: "limited"
editor:
invisibles: {}
showInvisibles: true
softTabs: false
tabType: "soft"
"exception-reporting":
userId: "<SOME_UUID>"
In Ansible I know I can load a JSON object and parse it with:
- name: Configure Atom IDE
shell: cat /home/"{{ cli_input_username }}"/.atom/config.cson
register: result
become_user: "{{ cli_input_username }}"
- set_fact:
atom_config_dict: "{{ result.stdout | from_json }}"
And then inspect some fields of that "JSON dictionary" with "{{ jsonVar['atom_config_dict."*".editor'] }}". I think this is going to work, but it may be I need to use some special tricks because of that asterisk used as a key of the dictionary "*".
But then how do I UPSERT (INSERT/UPDATE JSON key/values) some fields and save to file the whole JSON dictionary (after the changes) at ~/.atom/config.cson?
Do I have to treat special JSON keys as "*" in a specific way? Or is it just a string treated as a key of the dictionary?
How do I make sure the Ansible playbook can handle the fact that the configuration JSON file may not be there at the beginning? (e.g. when I am installing the Atom Editor IDE for the first time, i.e. at the first execution of the Ansible playbook).
EDIT:
I just realised this configuration file may not be an entirely valid JSON. In fact that file extension is "cson" which I am not familiar with.
So probably those tricks regarding from_json won't work.
Is there a way to deal with this configuration file in a structured way in order to make it searchable and parse it and then inser/update some keys of that dictionary? Perhaps this could be treated as a YAML file using from_yaml?
Atom works perfectly with a JSON file that stores your configuration. Simply convert the existing config.cson to JSON, delete (or rename) the file and place the converted config.json in its place.
To convert the file, you could use js2coffee (requires little editing) or the atomizr package for Atom. With the latter installed, simply open your config.cson and run the Atomizr: Toggle Atom Format command. Note that with the default settings, this will not keep the original file.
I have a Java code using selenium where I have a properties file which is in JSON format with multiple values and I want to use that file in Jenkins. For that I am using "This project is parameterized" option where I am selecting "File parameters" option.
So My question is How to use the JSON format in Jenkins? Am I doing is correct and what changes we have to make in code for that?
Can anyone help on this?
The "File parameters" is not working in the way you think, it is not like Jenkins will parse file and give you something like key/value map - no.
What is it doing is follwoing , you basically upload file and then how you use it is up to you, so in other words, if that file is for you java code, set the path for that file using the JVM params (e.g. -DpropertiesFilePath = ${abc.xyz}) and then Jenkins will parse the ${abc.xyz} for you and you java code will have proper path to file.
Otherwise, if you want to use the properties inside that JSON file itself for jenkins job configuration needs, then you have to write Jenkins job using either DSL or Jenkinsfile, in which having full access to file you can use for example JsonSlupper and parse Json file and assign properties to stages or whatever you need in Jenkins job walkthrow.