Skip to content

Commit d16c17f

Browse files
committed
feat: Allow single quoted strings in the output (starting JSON5)
1 parent 3580743 commit d16c17f

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
all: check build test
2+
3+
check:
4+
v fmt -w .
5+
v vet .
6+
7+
build:
8+
v yaml2json.v
9+
10+
test:
11+
./test.sh
12+
13+
version:
14+
npx conventional-changelog-cli -p angular -i CHANGELOG.md -s

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# yaml2json
22

3-
Converts [YAML] input to [JSON] output.
3+
Converts [YAML] input to [JSON]/[JSON5] output.
44

5-
Uses [prantlf.json] and [prantlf.yaml].
5+
Uses [prantlf.json] and [prantlf.yaml]. See also the [jsonlint] tool.
66

77
## Synopsis
88

@@ -21,6 +21,7 @@ Convert a file using standard input and standard output, as condensed as possibl
2121
Options:
2222
-o|--output <file> write the JSON output to a file
2323
-t|--trailing-commas insert trailing commas to arrays and objects
24+
-s|--single-quotes format single-quoted instead of double-quoted strings
2425
-l|--line-break append a line break to the JSON output
2526
-p|--pretty prints the JSON output with line breaks and indented
2627
-V|--version prints the version of the executable and exits
@@ -35,7 +36,15 @@ Convert a file using standard input and standard output, as condensed as possibl
3536
v vet .
3637
npx conventional-changelog-cli -p angular -i CHANGELOG.md -s
3738

39+
## TODO
40+
41+
This is a work in progress.
42+
43+
* Finish the [JSON5] support.
44+
3845
[prantlf.json]: https://github.com/prantlf/v-json
3946
[prantlf.yaml]: https://github.com/prantlf/v-yaml
47+
[jsonlint]: https://github.com/prantlf/v-jsonlint
4048
[JSON]: https://www.json.org/
49+
[JSON5]: https://spec.json5.org/
4150
[YAML]: https://yaml.org/

v.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Module {
22
name: 'yaml2json'
3-
description: 'Converts YAML input to JSON output.'
3+
description: 'Converts YAML input to JSON/JSON5 output.'
44
version: '0.0.4'
55
license: 'MIT'
66
dependencies: ['prantlf.cargs', 'prantlf.jany', 'prantlf.json', 'prantlf.yaml']

yaml2json.v

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import prantlf.yaml { parse_file, parse_text }
55

66
const version = '0.0.4'
77

8-
const usage = 'Converts YAML input to JSON output.
8+
const usage = 'Converts YAML input to JSON/JSON5 output.
99
1010
Usage: yaml2json [options] [<yaml-file>]
1111
12-
<yaml-file> read the YAML input from a file
12+
<yaml-file> read the YAML input from a file
1313
1414
Options:
1515
-o|--output <file> write the JSON output to a file
1616
-t|--trailing-commas insert trailing commas to arrays and objects
17+
-s|--single-quotes format single-quoted instead of double-quoted strings
1718
-l|--line-break append a line break to the JSON output
1819
-p|--pretty prints the JSON output with line breaks and indented
1920
-V|--version prints the version of the executable and exits
@@ -29,6 +30,7 @@ struct Opts {
2930
mut:
3031
output string
3132
trailing_commas bool
33+
single_quotes bool
3234
line_break bool
3335
pretty bool
3436
}
@@ -49,6 +51,7 @@ fn convert() ! {
4951
mut dst := stringify(src, StringifyOpts{
5052
pretty: opts.pretty
5153
trailing_commas: opts.trailing_commas
54+
single_quotes: opts.single_quotes
5255
})
5356
if opts.line_break {
5457
dst += '\n'

0 commit comments

Comments
 (0)