diff --git a/cffi/cdefs.h b/cffi/cdefs.h index e48a817..2f6cec9 100644 --- a/cffi/cdefs.h +++ b/cffi/cdefs.h @@ -315,6 +315,7 @@ LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint3 #define LYD_PARSE_LYB_MOD_UPDATE ... #define LYD_PARSE_NO_STATE ... #define LYD_PARSE_STORE_ONLY ... +#define LYD_PARSE_JSON_NULL ... #define LYD_PARSE_ONLY ... #define LYD_PARSE_OPAQ ... #define LYD_PARSE_OPTS_MASK ... diff --git a/libyang/context.py b/libyang/context.py index 1b1d4cd..ba3332a 100644 --- a/libyang/context.py +++ b/libyang/context.py @@ -520,6 +520,7 @@ def parse_data( validate_present: bool = False, validate_multi_error: bool = False, store_only: bool = False, + json_null: bool = False, ) -> Optional[DNode]: if self.cdata is None: raise RuntimeError("context already destroyed") @@ -531,6 +532,7 @@ def parse_data( ordered=ordered, strict=strict, store_only=store_only, + json_null=json_null, ) validation_flgs = validation_flags( no_state=no_state, @@ -589,6 +591,7 @@ def parse_data_mem( validate_present: bool = False, validate_multi_error: bool = False, store_only: bool = False, + json_null: bool = False, ) -> Optional[DNode]: return self.parse_data( fmt, @@ -604,6 +607,7 @@ def parse_data_mem( validate_present=validate_present, validate_multi_error=validate_multi_error, store_only=store_only, + json_null=json_null, ) def parse_data_file( @@ -620,6 +624,7 @@ def parse_data_file( validate_present: bool = False, validate_multi_error: bool = False, store_only: bool = False, + json_null: bool = False, ) -> Optional[DNode]: return self.parse_data( fmt, @@ -635,6 +640,7 @@ def parse_data_file( validate_present=validate_present, validate_multi_error=validate_multi_error, store_only=store_only, + json_null=json_null, ) def __iter__(self) -> Iterator[Module]: diff --git a/libyang/data.py b/libyang/data.py index 19ef0ca..0d63d3c 100644 --- a/libyang/data.py +++ b/libyang/data.py @@ -116,6 +116,7 @@ def parser_flags( ordered: bool = False, strict: bool = False, store_only: bool = False, + json_null: bool = False, ) -> int: flags = 0 if lyb_mod_update: @@ -132,6 +133,8 @@ def parser_flags( flags |= lib.LYD_PARSE_STRICT if store_only: flags |= lib.LYD_PARSE_STORE_ONLY + if json_null: + flags |= lib.LYD_PARSE_JSON_NULL return flags diff --git a/tests/test_data.py b/tests/test_data.py index 4b7914e..1479eb9 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -1131,3 +1131,9 @@ def test_merge_builtin_plugins_only(self): self.assertIsInstance(dnode, DLeaf) self.assertEqual(dnode.value(), "test") dnode.free() + + def test_dnode_parse_json_null(self): + JSON = """{"yolo-nodetypes:ip-address": null}""" + dnode = self.ctx.parse_data_mem(JSON, "json", json_null=True) + dnode_names = [d.name() for d in dnode.siblings()] + self.assertFalse("ip-address" in dnode_names)