Skip to content

Conversation

@pprindeville
Copy link
Member

@pprindeville pprindeville commented Sep 15, 2023

You might not always want to populate JSON serially, so a way to save/restore the cursor through a convenience function is handy.

Also, adding anonymous (unnamed) strings to an array isn't obvious, so added a convenience function for that.

Lastly, some minor cleanup to show what the parameters are to functions, etc.

Requires PR #16.

@pprindeville
Copy link
Member Author

@nbd168 Can I get a review please? I need some of these changes to help with a migration from ISC-DHCP to Kea.

@pprindeville
Copy link
Member Author

pprindeville commented Nov 4, 2023

cc: @Ansuel @dangowrt @neheb @stintel @jow-

@pprindeville
Copy link
Member Author

@jow- Can you please look this over?

@jow-
Copy link
Contributor

jow- commented Nov 20, 2023

Most (all?) existing functions use reference style returns (caller passes a destination variable name, function populates it and uses it's numeric return value to signify success/error) while your new functions introduce echo style returns requiring calling code to use ugly subshell invocations.

Personally I would also change the naming like that:

  • json_get_pos -> json_get_position
  • json_set_pos -> json_move_to
  • json_get_parent -> json_move_up
  • json_add_anon_string -> json_push_string

@pprindeville
Copy link
Member Author

pprindeville commented Nov 21, 2023

Most (all?) existing functions use reference style returns (caller passes a destination variable name, function populates it and uses it's numeric return value to signify success/error) while your new functions introduce echo style returns requiring calling code to use ugly subshell invocations.

Personally I would also change the naming like that:

  • json_get_pos -> json_get_position
  • json_set_pos -> json_move_to
  • json_get_parent -> json_move_up
  • json_add_anon_string -> json_push_string

Thanks, making those changes now.

By json_get_pos you meant json_get_cur, and that should become json_get_position?

And json_set_cur should become json_move_to? Or json_set_position (for symmetry)?

Where do the functions _get_var and _set_var get used? I can only find references to _json_get_var and _json_set_var...

json_get_parent isn't meant to move the cursor explicitly. It's a way to get the parent of a node if you need to do something like query the parent's type (array, table, etc).

For instance, you could implement json_select ".." as:

    local parent
    json_get_parent parent
    json_set_position "$parent"

if json_select ".." didn't exist.

@pprindeville pprindeville force-pushed the jshn-more-improvements branch from 104f923 to 02b2c90 Compare November 21, 2023 01:35
@pprindeville
Copy link
Member Author

Casting a wider net

cc: @blogic

@pprindeville
Copy link
Member Author

Creating 2nd PR (#12) without the positioning getter/setting commit which seems to be stalled.

@pprindeville
Copy link
Member Author

Most (all?) existing functions use reference style returns (caller passes a destination variable name, function populates it and uses it's numeric return value to signify success/error) while your new functions introduce echo style returns requiring calling code to use ugly subshell invocations.

Personally I would also change the naming like that:

  • json_get_pos -> json_get_position
  • json_set_pos -> json_move_to
  • json_get_parent -> json_move_up
  • json_add_anon_string -> json_push_string

@jow- I believe I've made these changes as requested. Can you please re-review?

@pprindeville pprindeville force-pushed the jshn-more-improvements branch 2 times, most recently from 3ba2872 to d1f6263 Compare August 4, 2024 21:35
@pprindeville
Copy link
Member Author

@jow- I believe I've addressed the comments you made. Can I get a merge please or a re-review?

@pprindeville
Copy link
Member Author

@nbd168 Can I get a review please? I need some of these changes to help with a migration from ISC-DHCP to Kea.

Still blocked on improvements to libubox before I can merge these this migration tool to Kea.

@Neustradamus
Copy link

This migration is really important from ISC DHCP to Kea.

@systemcrash
Copy link

I figure you have commit rights to fix this @pprindeville

@pprindeville
Copy link
Member Author

I figure you have commit rights to fix this @pprindeville

No, my rights are only for openwrt/packages.

@pprindeville pprindeville force-pushed the jshn-more-improvements branch from d1f6263 to 7ef9c6f Compare November 11, 2025 20:48
@systemcrash
Copy link

Get the test formalities fixed and then we can ping a maintainer.

@pprindeville
Copy link
Member Author

Get the test formalities fixed and then we can ping a maintainer.

Do you know how to write test scripts? I've not dug into it.

@systemcrash
Copy link

systemcrash commented Nov 12, 2025

?

: Commit subject line MUST start with '<package name>: ' (jshn.sh: Add getters for the cursor and its parent)

@pprindeville
Copy link
Member Author

?

: Commit subject line MUST start with '<package name>: ' (jshn.sh: Add getters for the cursor and its parent)

Is that a new requirement?

ca3f6d0 udebug: fix file descriptor initialization for __udebug_buf_map
6339204 CMakeLists.txt: bump minimum cmake version
c1be505 udebug: fix crash in udebug_entry_vprintf with longer strings
a2fce00 CI: add build test run
12bda4b CI: add CodeQL workflow tests
eb9bcb6 ustream: prevent recursive calls to the read callback
3868f47 blob: constify attr argument to blob_memdup
b7acc8e remove compatibility code for older json-c versions
a1acd99 udebug: remove obsolete debug message
49056d1 udebug: fix issue with snapshot of remote ring
eeb6fcf examples: CMakeLists: update cmake minimum required version to 3.10
c163d7a lua: build: require CMake >= 3.10 due to dropped legacy support
7a3863a lua: CMakeLists: drop redundant cmake_minimum_required
61cc1e6 examples: CMakeLists: drop redundant cmake_minimum_required
7d6b9d9 add debian/ directory
9caf555 (origin/master) github: improve CI build

@pprindeville pprindeville force-pushed the jshn-more-improvements branch from 7ef9c6f to 937a88e Compare November 12, 2025 00:51
@pprindeville pprindeville changed the title jshn.sh: add convenience functions, cleanup libubox: add convenience functions, cleanup Nov 12, 2025
@pprindeville pprindeville force-pushed the jshn-more-improvements branch from 937a88e to bc91ae7 Compare November 12, 2025 02:34
JSON might not be generated serial if it's synthesized from another
source such as UCI with a different organizational structure.  In
that case, being able to randomly access arrays and objects in the
synthetic JSON simplifies passes over the source material.

Signed-off-by: Philip Prindeville <[email protected]>
@pprindeville pprindeville force-pushed the jshn-more-improvements branch from bc91ae7 to f97afd4 Compare November 12, 2025 02:36
@pprindeville
Copy link
Member Author

Get the test formalities fixed and then we can ping a maintainer.

Do you know how to write test scripts? I've not dug into it.

Sorry, misread. Thought you were suggesting we add test coverage as well. Which doesn’t seem like a bad idea.

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.

4 participants