Skip to content

Conversation

@pprindeville
Copy link
Member

@pprindeville pprindeville commented Nov 14, 2025

When adding anonymous objects to an array, the only way to select them (as in json_select) is via their ordinality. This function returns a selectable index to those members.

@pprindeville
Copy link
Member Author

cc: @robimarko @ynezz

@pprindeville
Copy link
Member Author

pprindeville commented Nov 17, 2025

@ynezz Any idea why the test is failing with:

...
test_jshn_append_no_leading_space
test_jshn_get_index
/home/runner/work/libubox/libubox/tests/shunit2/tests.sh: 1: eval: JSON_UNSET: parameter not set

Errors while running CTest

50% tests passed, 1 tests failed out of 2

Total Test time (real) =  45.45 sec

The following tests FAILED:
	  2 - shunit2 (Failed)
make: *** [Makefile:71: test] Error 8

It looks like a problem with setup or teardown of the test. Trying to go by your example, it calls __jshn_append which is an internal, low-level function... I don't see any examples that use the user-visible functions that I can follow as a template.

cc: @Noltari

@Noltari
Copy link
Member

Noltari commented Nov 17, 2025

@ynezz Any idea why the test is failing with:

...
test_jshn_append_no_leading_space
test_jshn_get_index
/home/runner/work/libubox/libubox/tests/shunit2/tests.sh: 1: eval: JSON_UNSET: parameter not set

Errors while running CTest

50% tests passed, 1 tests failed out of 2

Total Test time (real) =  45.45 sec

The following tests FAILED:
	  2 - shunit2 (Failed)
make: *** [Makefile:71: test] Error 8

It looks like a problem with setup or teardown of the test. Trying to go by your example, it calls __jshn_append which is an internal, low-level function... I don't see any examples that use the user-visible functions that I can follow as a template.

cc: @Noltari

@pprindeville adding set +u as @ynezz did on #30 seems to fix the issue you're having:

test_jshn_get_index() {
	JSON_PREFIX="${JSON_PREFIX:-}"
	. ../../sh/jshn.sh

	set +u

	local index

	json_init
	json_add_object "Dhcp4"

	json_add_array "subnet4"

	json_add_object ""
	json_get_index index

	json_add_int "id" 1
	json_add_string "subnet" "192.168.1.0/24"

	json_close_object

	json_add_object ""

	json_add_int "id" 2
	json_add_string "subnet" "192.168.2.0/24"

	json_close_object

	json_select "$index"		# revisit first anonymous object
	json_add_int "valid-lifetime" 3600
	json_select ..			# pop back into array

	json_close_array		# subnet4

	json_close_object		# Dhcp4

	local json="$(json_dump)"

	assertEquals '{ "Dhcp4": { "subnet4": [ { "id": 1, "subnet": "192.168.1.0\/24", "valid-lifetime": 3600 }, { "id": 2, "subnet": "192.168.2.0\/24" } ] } }' "$json"

	set -u
}

(And removing one of the double \ in the subnets)

@Noltari
Copy link
Member

Noltari commented Nov 17, 2025

@pprindeville you need to rebase it on top of #34 in order to get it working.

@Noltari Noltari force-pushed the add-get-index branch 2 times, most recently from 2204038 to f6c19dd Compare November 17, 2025 12:24
@Noltari Noltari force-pushed the add-get-index branch 2 times, most recently from 52309f9 to 6f6958b Compare November 17, 2025 18:15
@Noltari
Copy link
Member

Noltari commented Nov 17, 2025

@pprindeville I rebased your branch on top of master, and made some minor changes.
It would be great if other OpenWrt developers could review this since I don't really have a deep libubox knowledge...

CC @nbd168 @ynezz @jow-

Noltari pushed a commit to pprindeville/libubox that referenced this pull request Nov 17, 2025
When adding anonymous objects to an array, the only way to select
those objects (as in "json_select", i.e. moving the cursor) is to
select them via their ordinality.

This function returns a selectable index to those objects.

Signed-off-by: Philip Prindeville <[email protected]>
Link: openwrt#33
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
pprindeville added a commit to pprindeville/libubox that referenced this pull request Nov 19, 2025
When adding anonymous objects to an array, the only way to select
those objects (as in "json_select", i.e. moving the cursor) is to
select them via their ordinality.

This function returns a selectable index to those objects.

Signed-off-by: Philip Prindeville <[email protected]>
Link: openwrt#33
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
@pprindeville
Copy link
Member Author

pprindeville commented Nov 21, 2025

@pprindeville I rebased your branch on top of master, and made some minor changes. It would be great if other OpenWrt developers could review this since I don't really have a deep libubox knowledge...

@Noltari Understood. Given that getting traction on this package has been challenging, and that the new function isn't callable anywhere else but by Kea, should we merge it in the absence of objections in... say... 2 weeks?

When adding anonymous objects to an array, the only way to select
those objects (as in "json_select", i.e. moving the cursor) is to
select them via their ordinality.

This function returns a selectable index to those objects.

Signed-off-by: Philip Prindeville <[email protected]>
Link: openwrt#33
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants