Add :ALWAYS-ITEM parsing-option

When toggled, /everything/ will be parsed as a
JSON-LD object, even if it an invalid one.
This commit is contained in:
Jaidyn Ann 2024-09-03 11:10:50 -05:00
parent 8faeb1afd2
commit ce557da89c

View File

@ -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." parsed into hash-tables) will be parsed into CLOS objects."
(let ((ctx (make-hash-table :test #'equal)) ; Parsed context (let ((ctx (make-hash-table :test #'equal)) ; Parsed context
(parsed (yason:parse str))) (parsed (yason:parse str)))
(when always-object
(setf (gethash ".always-object" ctx) 't))
(values (parse-item parsed ctx) (values (parse-item parsed ctx)
ctx))) ctx)))
@ -326,8 +328,11 @@ parsed into hash-tables) will be parsed into CLOS objects."
(let* ((parsed-table (parse-table-inplace table ctx)) (let* ((parsed-table (parse-table-inplace table ctx))
(type (identify-json-type parsed-table ctx)) (type (identify-json-type parsed-table ctx))
(type-def (or (gethash type *json-types*) (type-def (or (gethash type *json-types*)
(gethash *default-json-type* *json-types*)))) (gethash *default-json-type* *json-types*)))
(parse-table-into-object parsed-table type-def ctx)))) (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) (defun parse-table-inplace (table ctx)
"Expand a YASON-parsed JSON-LD node-object in TABLE. That is, replace all "Expand a YASON-parsed JSON-LD node-object in TABLE. That is, replace all