shyaml icon indicating copy to clipboard operation
shyaml copied to clipboard

Idea: put-value

Open kseistrup opened this issue 11 years ago • 4 comments

Would it be possible to create a version of shyaml/shjson that manipulated key-value pairs? E.g.:

$ echo '{"a": 1, "b": 2}' | shjson put-value c 3
{
  "a": 1,
  "b": 2,
  "c": 3
}

or

$ echo '{"a": 1, "b": 2}' | shjson put-value b 7
{
  "a": 1,
  "b": 7
}

?

kseistrup avatar Apr 28 '13 09:04 kseistrup

Yup, good idea. Will have to specify types also, and limit it to simples types at first. If you have some proposition to enter/build complex types (struct or list) thanks to the command line, I'm open ;)

vaab avatar Apr 30 '13 21:04 vaab

Here's a quick thought on this topic. Nothing really valuable, I'm throwing ideas here in case.

To answer my own question, the way to enter complex types thanks to the command line could be... in shjson itself.

$ cat <<EOF | shjson put-value b.x '{"u": 1, "v": 2}'
{
    "a": [1, "foo"],
    "b": {"x": 1, "y": 2},
    "c": 3
}
EOF
{
    "a": [1, "foo"],
    "b": {"x": {"u": 1, "v": 2},
          "y": 2},
    "c": 3
}

For literal values you would need to double-quote though:

$ ...  | shjson put-value b.x '"my string"'

vaab avatar Jan 03 '15 02:01 vaab

I'm tempted to take queues from jq here (assuming everything to be a string, but providing functions to cast/interpret to other types).

charles-dyfis-net avatar Apr 03 '15 18:04 charles-dyfis-net

Good idea, just name it "set" instead of "put". Everyone is using get/set, less HTTP but that's a very different case.

ssbarnea avatar Jul 28 '17 18:07 ssbarnea