diff --git a/User Guide.md b/User Guide.md index c927d51..406e763 100644 --- a/User Guide.md +++ b/User Guide.md @@ -113,8 +113,10 @@ ## Displaying JSON ### Pretty printing -If no argument given, `jtc` will expect an input JSON from the ``, otherwise JSON is read from the file(s) pointed by the -argument(s). `jtc` will parse and validate input JSON and upon a successful validation will output: +If no argument is given, `jtc` will read JSON from ``, otherwise JSON +will be read from the files specified. `jtc` will parse and validate input JSON +and upon successful validation the JSON will be output: + ```bash bash $ :1214): unexpected_end_of_line -bash $ +bash $ ``` -and though the message lets us knowing that there's a problem with the input JSON, it not very informative with regards whereabouts the -the problem. To visualize the spot where the problem is, as well as its locus pass a single debug option (`-d`): + +The error messsage doesn't explain where the problem is, the `-d` flag (single +debug) will help: + ```bash bash $ | (offset: 1214) jtc json parsing exception (:1214): unexpected_end_of_line -bash $ +bash $ ``` -the vertical pipe symbol `|` in the debug showing JSON locus replaces new lines, thus it becomes easy to spot the problem. -The offset (`1214` in the example) is given in _unicode UTF-8_ characters from the beginning of the input/file/stream. -In that particular failure instance, `jtc` found the end of a line, while _JSON string_ `"Co,` is still open (JSON standard does not -permit multi-line strings). To fix that, the missing quotation mark to be added + +The vertical pipe symbol `|` in the debug output shows the location +(`exception_locus .. offset:1214`) of the problem. + +The offset (`1214` in the example) is given in _unicode UTF-8_ characters from +the beginning of the input/file/stream. In this example `jtc` found an +unexpected end of line in `"CO,` (the JSON standard doesn't permit multi-line +strings). To fix this, the missing quotation mark must be added. + +Multiple debug flags (`-dd`, `-ddd`, etc) can be used to gain greater insight. ### Forcing strict solidus parsing -JSON specification allows escaping solidus (`/`) optionally. By default, `jtc` is relaxed w.r.t. parsing solidus notation - it admits -both unescaped and escaped appearances: + +The JSON specification allows optional escaping of solidus (`/`). By default, +`jtc` is looser and allows both unescaped and escaped input: + ```bash bash $ <<<'{ "escaped": "\/", "unescaped": "/" }' jtc { @@ -330,8 +354,9 @@ bash $ <<<'{ "escaped": "\/", "unescaped": "/" }' jtc } bash $ ``` -If there's a need for a strict solidus parsing, option `-q` facilitates the need. It also will throw an exception upon facing -a non-escaped notation: + +The `-q` flag will enforce strict solidus parsing: + ```bash bash $ <<<'{ "escaped": "\/", "unescaped": "/" }' jtc -q -d .display_opts(), option set[0]: -q -d (internally imposed: ) @@ -343,8 +368,10 @@ bash $ ``` ### Unquoting JSON strings -If a JSON itself (or a result from walking JSON) is a single JSON string, then sometimes there's a need to unquote it -(especially it comes handy if the string itself is an embedded JSON). `-qq` allows unquoting it, here are a few examples: + +Sometimes JSON needs unquoting (for example with embedded JSON), the `-qq` flag +supports this: + ```bash bash $ jsn='"{ \"JSON\": \"example of an embedded JSON\" }"' bash $ <<<$jsn jtc @@ -362,7 +389,8 @@ bash $ <<<$jsn jtc -qq | jtc bash $ ``` -When unquoting empty _JSON strings_ (`""`) the resulted blank lines are not even printed: +When unquoting empty _JSON strings_ (`""`) the resulting blank lines aren't printed: + ```bash bash $ <<<'[null, "", true]' jtc -w[:] -qq null @@ -370,8 +398,9 @@ true bash $ ``` -If the source string contains Unicode code points, those will be correctly translated into -respective UTF-8 characters: +If the source string contains Unicode code points, it will be correctly +translated to UTF-8 characters: + ```bash bash $ <<<'"Unicode char: \u1234"' jtc -qq Unicode char: ሴ @@ -384,7 +413,6 @@ jtc json exception: invalid_surrogate_code_pair bash $ ``` - > NOTE: _the option notation `-qq` will not engulf a single option notation `-q`, if both behaviors are required then both variants have to be spelled (e.g. `jtc -q -qq`, or `jtc -qqq`)_ > Also, `-qq` is incompatible with `-j`, `-J` options, because of a risk of forming an ill-formed JSON, thus, when sighted together