|
1 | 1 | # dotnet-json |
2 | 2 |
|
3 | | -[](https://www.nuget.org/packages/dotnet-json/) |
| 3 | +[](https://www.nuget.org/packages/dotnet-json/) |
4 | 4 |
|
5 | | -.NET Core 3.1 global tool for manipulating JSON files. |
| 5 | +dotnet-json is a command line tool for working with and manipulating JSON files for example in CI/CD pipelines. |
| 6 | + |
| 7 | +dotnet-json allows you to do basic manipulation of JSON files like setting the value of a specific (nested) key, or deleting a key, |
| 8 | +as well as merging two or more JSON files into one. |
6 | 9 |
|
7 | 10 | ## Installation |
8 | 11 |
|
9 | | -`dotnet tool install -g dotnet-json` |
| 12 | +dotnet-json can be installed as a .NET Core (global) tool or be downloaded directly from the [GitHub releases](https://github.com/sleeuwen/dotnet-json/releases). |
10 | 13 |
|
11 | | -## Usage |
| 14 | +To install dotnet-json as a global tool, run the following command: |
12 | 15 |
|
13 | 16 | ``` |
14 | | -dotnet-json: |
15 | | - JSON .NET Global Tool |
| 17 | +dotnet tool install -g dotnet-json |
| 18 | +``` |
16 | 19 |
|
17 | | -Usage: |
18 | | - dotnet-json [options] [command] |
| 20 | +## Usage |
19 | 21 |
|
20 | | -Options: |
21 | | - --version Show version information |
22 | | - -?, -h, --help Show help and usage information |
| 22 | +When you installed dotnet-json as a .NET Core global tool, you can run it as either `dotnet json` or `dotnet-json`. |
23 | 23 |
|
24 | | -Commands: |
25 | | - merge <file> <files> merge two or more json files into one |
26 | | - set <file> <key> <value> set a value in a json file |
27 | | - remove, rm <file> <key> Remove a value from the json |
28 | | - get <file> <key> Read a value from a JSON file. |
29 | | -``` |
| 24 | +dotnet-json has 4 sub-commands, `merge`, `set`, `remove` and `get`. |
30 | 25 |
|
31 | | -### Commands |
32 | | - |
33 | | -#### Merge |
| 26 | +### Merge |
34 | 27 |
|
35 | 28 | Merges two or more files into the first, writing it back to the first file or into a specified output file. |
36 | 29 |
|
| 30 | +**Usage:** |
| 31 | +``` |
| 32 | +dotnet json merge <input file> <merge files...> [-o|--output <output file>] |
37 | 33 | ``` |
38 | | -merge: |
39 | | - merge two or more json files into one |
40 | 34 |
|
41 | | -Usage: |
42 | | - dotnet-json merge [options] <file> <files>... |
| 35 | +**Arguments:** |
43 | 36 |
|
44 | | -Arguments: |
45 | | - <file> The JSON file (use '-' for STDIN) |
46 | | - <files> The names of the files to merge with the first file. |
| 37 | +- _\<input file>_ The first JSON file used as base to merge the other files' contents into, also used as default output |
| 38 | +- _\<merge files...>_ One or more JSON files that are merged into the first file |
47 | 39 |
|
48 | | -Options: |
49 | | - -o, --output <file> The output file (use '-' for STDOUT, defaults to <file>) |
50 | | - -?, -h, --help Show help and usage information |
51 | | -``` |
| 40 | +**Options:** |
| 41 | +- _-o|--output file_ Write the merge result to a custom output file instead of using the input file |
52 | 42 |
|
53 | | -#### Set |
| 43 | +### Set |
54 | 44 |
|
55 | | -Updates the json file to set a value for a key. Use `:` as separator for nesting objects. |
| 45 | +Set a specific value in the JSON file. Use `:` as separator for nesting objects. |
56 | 46 |
|
| 47 | +**Usage:** |
| 48 | +``` |
| 49 | +dotnet json set <file> <key> <value> [-o|--output <output file>] |
57 | 50 | ``` |
58 | | -set: |
59 | | - set a value in a json file |
60 | | -
|
61 | | -Usage: |
62 | | - dotnet-json set [options] <file> <key> <value> |
63 | 51 |
|
64 | | -Arguments: |
65 | | - <file> The JSON file (use '-' for STDIN) |
66 | | - <key> The key to set (use ':' to set nested object and use index numbers to set array values eg. nested:key or nested:1:key) |
67 | | - <value> The value to set |
| 52 | +**Arguments:** |
| 53 | +- _\<file>_ The file to read the JSON from and write the result to unless `-o` is given. |
| 54 | +- _\<key>_ The key to update or create, use `:` to separate nested objects. |
| 55 | +- _\<value>_ The value to set the key to |
68 | 56 |
|
69 | | -Options: |
70 | | - -o, --output <file> The output file (use '-' for STDOUT, defaults to <file>) |
71 | | - -?, -h, --help Show help and usage information |
72 | | -``` |
| 57 | +**Options:** |
| 58 | +- _-o|--output file_ Write the result to a custom output file instead of using the input file |
73 | 59 |
|
74 | | -#### remove |
| 60 | +### remove |
75 | 61 |
|
76 | | -Updates the json file to remove a key from the file. Use `:` as separator for nested objects. |
| 62 | +Removes a key/value pair or complex object from a JSON file. |
77 | 63 |
|
| 64 | +**Usage:** |
| 65 | +``` |
| 66 | +dotnet json remove <file> <key> [-o|--output <output file>] |
78 | 67 | ``` |
79 | | -remove: |
80 | | - Remove a value from the json |
81 | | -
|
82 | | -Usage: |
83 | | - dotnet-json remove [options] <file> <key> |
84 | 68 |
|
85 | | -Arguments: |
86 | | - <file> The JSON file (use '-' for STDIN) |
87 | | - <key> The JSON key to remove |
| 69 | +**Arguments:** |
| 70 | +- _\<file>_ The file to read the JSON from and write the result to unless `-o` is given. |
| 71 | +- _\<key>_ The key to remove from the read JSON |
88 | 72 |
|
89 | | -Options: |
90 | | - -o, --output <file> The output file (use '-' for STDOUT, defaults to <file>) |
91 | | - -?, -h, --help Show help and usage information |
92 | | -``` |
| 73 | +**Options:** |
| 74 | +- _-o|--output file_ Write the result to a custom output file instead of using the input file |
93 | 75 |
|
94 | | -#### get |
| 76 | +### get |
95 | 77 |
|
96 | 78 | Reads the json file and returns the value for the given key. |
97 | 79 |
|
| 80 | +**Usage:** |
| 81 | +``` |
| 82 | +dotnet json get <file> <key> [-e|--exact] |
98 | 83 | ``` |
99 | | -get: |
100 | | - Read a value from a JSON file. |
101 | | -
|
102 | | -Usage: |
103 | | - dotnet-json get [options] <file> <key> |
104 | 84 |
|
105 | | -Arguments: |
106 | | - <file> The JSON file (use '-' for STDIN) |
107 | | - <key> The key to get (use ':' to get a nested object and use index numbers to get array values eg. nested:key or nested:1:key) |
| 85 | +**Arguments:** |
| 86 | +- _\<file>_ The file to read the JSON from. |
| 87 | +- _\<key>_ The key to output |
108 | 88 |
|
109 | | -Options: |
110 | | - -e, --exact only return exact value matches, this will return an error for references to nested objects/arrays. |
111 | | - -?, -h, --help Show help and usage information |
112 | | -``` |
| 89 | +**Options:** |
| 90 | +- _-e|--exact_ only return an exact value, this will return an error if the key references an object or array. |
0 commit comments