From ce557da89ccf47bde249b57f8fb16d886f90b40b Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:10:50 -0500 Subject: [PATCH] Add :ALWAYS-ITEM parsing-option When toggled, /everything/ will be parsed as a JSON-LD object, even if it an invalid one. --- src/json-ld.lisp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/json-ld.lisp b/src/json-ld.lisp index 867b2a3..d2b0262 100644 --- a/src/json-ld.lisp +++ b/src/json-ld.lisp @@ -309,6 +309,8 @@ If ALWAYS-OBJECT is non-nil, even invalid JSON-LD objects (which would normally parsed into hash-tables) will be parsed into CLOS objects." (let ((ctx (make-hash-table :test #'equal)) ; Parsed context (parsed (yason:parse str))) + (when always-object + (setf (gethash ".always-object" ctx) 't)) (values (parse-item parsed ctx) ctx))) @@ -326,8 +328,11 @@ parsed into hash-tables) will be parsed into CLOS objects." (let* ((parsed-table (parse-table-inplace table ctx)) (type (identify-json-type parsed-table ctx)) (type-def (or (gethash type *json-types*) - (gethash *default-json-type* *json-types*)))) - (parse-table-into-object parsed-table type-def ctx)))) + (gethash *default-json-type* *json-types*))) + (valid-object (or type (gethash "@id" table)))) + (if (or valid-object (gethash ".always-object" ctx)) + (parse-table-into-object parsed-table type-def ctx) + parsed-table)))) (defun parse-table-inplace (table ctx) "Expand a YASON-parsed JSON-LD node-object in TABLE. That is, replace all