[LEDE-DEV] jshn.sh: json_load replaces "-" with "_"
Matthias Schiffer
mschiffer at universe-factory.net
Sun Oct 29 19:28:55 PDT 2017
On 10/29/2017 09:21 PM, Paul Spooren wrote:
> Hi all,
>
> I'm currently trying to use jshn.sh but it changes the data and makes it
> unusable.
>
> Below an example:
>
> root at LEDE:~# json_string="{ \"foo-bar\": 10 }"
> root at LEDE:~# echo $json_string
> { "foo-bar": 10 }
> root at LEDE:~# json_init
> root at LEDE:~# json_load "$json_string"
> root at LEDE:~# json_dump
> { "foo_bar": 10 }
>
> Expected would be the same output as input. Is this a bug or a feature?
>
> Context:
>
> Running snapshot build. I'm trying to use rpcd-mod-packagelist [1] but
> as e.g. "kmod-r8169" becomes "kmod_r8169" it's useless.
>
> Best,
>
> Paul Spooren
>
> [1]:
> https://github.com/openwrt/packages/tree/master/utils/rpcd-mod-packagelist
This is definitely a bug in jshn.sh (or possibly a "known limitation" to
keep the code simple, as shell variable names can't contain dashes). It
should be possible to fix this in jshn with some clever escaping of keys -
at least for such "simple" special characters (without looking into it in
detail, I assume other unusual characters that aren't allowed in shell
variable names are also an issue; supporting the full range of unicode
might need more work, or entail a prohibitive performance penalty.)
It might actually be much easier to fix the concrete issue by rewriting
rpcd-mod-packagelist in C (as I suggested in [2]).
Matthias
[2] https://github.com/openwrt/packages/pull/5037
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20171030/aeee7f76/attachment.sig>
More information about the Lede-dev
mailing list