From 53d21eaffca921b71ce6eb9a75bc3d82897e89b6 Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Wed, 20 Sep 2023 12:09:18 -0400 Subject: [PATCH] Add example of adding/updating a field that contains periods JSON assumes periods indicate an inner context. That's not always true. See issue 159. This adds an example to the docs based on the suggested solution. --- docs/json.1.html | 10 ++++++++++ docs/json.1.ronn | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/json.1.html b/docs/json.1.html index 3f2a267..56fd6f2 100644 --- a/docs/json.1.html +++ b/docs/json.1.html @@ -538,6 +538,16 @@

FEATURE: In-place editing

"hostname": "127.0.0.1", "port": 8080 } + +# add/update field that contains periods +$ json -I -f config.json -e 'this["field.with.periods"]="update"' +json: updated "config.json" in-place +$ cat config.json +{ + "hostname": "127.0.0.1", + "port": 8080, + "field.with.periods": "update" +}

Some limitations. Only one file at a time:

diff --git a/docs/json.1.ronn b/docs/json.1.ronn index 08ec8e4..78cec1e 100644 --- a/docs/json.1.ronn +++ b/docs/json.1.ronn @@ -425,6 +425,16 @@ You can edit a file in place with `-I` and `-f FILE`: "port": 8080 } + # add/update field that contains periods + $ json -I -f config.json -e 'this["field.with.periods"]="update"' + json: updated "config.json" in-place + $ cat config.json + { + "hostname": "127.0.0.1", + "port": 8080, + "field.with.periods": "update" + } + Some limitations. Only one file at a time: $ json -I -f foo.json -f bar.json