Commit graph

34 commits

Author SHA1 Message Date
Jo-Philipp Wich
bd388d2b6c jshn: do not collapse whitespace in json_load()
When running the test case below the $key variable holds "foo bar" instead
of the expected "foo  bar".

-- 8< --
. /usr/share/libubox/jshn.sh
json_init
json_load '{ "key": "foo  bar" }'
json_get_var key key
-- >8 --

Quote the output of the "jshn -r" backtick expression to prevent the shell
from erroneously collapsing whitespace.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2014-07-16 20:36:13 +02:00
Bastian Bittorf
51766c25e9 sh/jshn.sh - json_cleanup() dont pollute env with local vars
this script is mostly sourced, so we should try to keep the pollution
of the users environment as low as possible. make the var 'tmp' local

Signed-off-by: Bastian Bittorf <bittorf@bluebottle.com>
2014-04-26 21:30:33 +02:00
Felix Fietkau
43d2d349cb jshn: drop json_select warnings when called from json_get_values()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-02 15:22:23 +01:00
Jo-Philipp Wich
e58fa88e1f jshn: add ability to pass default values to json_get_var and json_get_vars 2013-12-10 17:30:15 +00:00
Felix Fietkau
318d682d29 jshn: in json_get_values(), handle json_select errors
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-12-02 10:56:54 +01:00
Felix Fietkau
9636c0e79c jshn: optimize the shell code some more
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-12-01 22:06:16 +01:00
Felix Fietkau
a34c8f6918 jshn: refactor _jshn_append to require fewer evals
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-30 11:50:39 +01:00
Felix Fietkau
dcbc14a701 jshn: improve performance by getting rid of unnecessary variables in parser related code
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-30 11:36:46 +01:00
Felix Fietkau
2d4ce122c4 jshn: do not export SEQ_*
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-30 10:58:34 +01:00
Felix Fietkau
1a32939cb5 jshn: get rid of the table stack, use the UP_* variable instead to speed up processing
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-30 10:58:34 +01:00
Felix Fietkau
554ed49c15 jshn: reduce the number of appends to the cleanup list to speed up processing of large json files
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-30 10:57:51 +01:00
Felix Fietkau
b7e61837e7 jshn: allow json_get_keys/values to refer to the currently selected array/table if no argument is given
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-29 15:11:42 +01:00
Felix Fietkau
b5aa522f5d jshn: add json_get_values (useful for arrays)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-29 14:59:47 +01:00
Felix Fietkau
4bc1a3a46b jshn: add json_get_keys()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-20 00:00:42 +02:00
Felix Fietkau
00a833c5b6 jshn: add support for the double datatype
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-03-17 00:50:03 +01:00
Luka Perkov
220958b7d9 rename internal variables in json_get_type
Signed-off-by: Luka Perkov <luka@openwrt.org>
2013-01-17 13:34:55 +01:00
Luka Perkov
f1735cd94e sanitize json_get_type function
Signed-off-by: Luka Perkov <luka@openwrt.org>
2013-01-04 13:28:08 +01:00
Felix Fietkau
4d0a00c82c jshn: fix check to reset array sequence counters on cleanup 2012-12-18 13:38:27 +01:00
Jo-Philipp Wich
0505bf5f42 jshn: introduce json_is_a() convenience function to check field types without using a temporary variable 2012-12-17 13:54:45 +01:00
Felix Fietkau
079549666f jshn: fix array handling
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-12-16 19:58:06 +01:00
Felix Fietkau
7bca5dd29d jshn: fix some variable handling regressions
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-12-16 18:04:14 +01:00
Felix Fietkau
e16fa068a5 jshn: add support for namespaces
Can be used to fix variable namespace clashes in library code using jshn

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-12-16 17:46:08 +01:00
Jo-Philipp Wich
0608d12995 sh/jshn.sh: fix json_get_var() and json_get_type() to not return cached values 2012-05-30 21:47:43 +02:00
Jo-Philipp Wich
67bc554465 sh/jshn.sh: replace "tr" calls with inline substitution, signalize success with return values 2012-05-29 02:12:35 +02:00
Felix Fietkau
94ff2a0abb sh/jshn.sh: fix allowing numbers in identifiers
json_add_generic() needs to handle them as well
2012-05-17 14:30:00 +02:00
Jo-Philipp Wich
592f2dbd82 sh/jshn.sh: allow numbers in identifiers for json_get_var()
When traversing arrays of tables or arrays of array it is required to
call json_select # where # is the index of the array item to select.

Internally json_select() calls json_get_var() to obtain the correct
prefix to populate $JSON_CUR with. However, the "tr" call in
json_get_var() incorrectly replaces all digits with underscores,
making any lookup for numeric array items fail.

The attached patch changes the "tr" expression to allow digits and
thus implements the expected behaviour for nested arrays.
2012-05-16 10:42:37 +02:00
Felix Fietkau
97ed91fa77 jshn.sh: add json_get_vars() wrapper function 2012-05-14 00:21:12 +02:00
Felix Fietkau
738884e746 same for json_get_var 2011-09-11 11:46:44 +02:00
Felix Fietkau
a1a97eb11e jshn: support using characters in elements that do not conform to shell variable restrictions 2011-09-11 11:40:22 +02:00
Felix Fietkau
ec56b91662 jshn: clear more variables on json_init, fix adding array elements 2011-08-11 15:29:23 -06:00
Felix Fietkau
bdf6363777 jshn: add an option for printing the json data without a terminating newline 2011-05-31 15:41:19 +02:00
Felix Fietkau
11079ba582 jshn: fix invalid variable reuse 2011-05-23 23:15:33 +02:00
Felix Fietkau
cc2457aa3e jshn: do not use -n on export 2011-05-23 23:09:19 +02:00
Felix Fietkau
fda6079b30 add jshn 2011-05-23 22:21:27 +02:00