texlive[73532] Master/texmf-dist: jsonparse (20jan25)

commits+karl at tug.org commits+karl at tug.org
Mon Jan 20 22:26:14 CET 2025


Revision: 73532
          https://tug.org/svn/texlive?view=revision&revision=73532
Author:   karl
Date:     2025-01-20 22:26:14 +0100 (Mon, 20 Jan 2025)
Log Message:
-----------
jsonparse (20jan25)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/jsonparse/README.md
    trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf
    trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex
    trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty

Modified: trunk/Master/texmf-dist/doc/latex/jsonparse/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/jsonparse/README.md	2025-01-20 21:26:05 UTC (rev 73531)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/README.md	2025-01-20 21:26:14 UTC (rev 73532)
@@ -1,4 +1,4 @@
-![Version 0.9.12](https://img.shields.io/badge/version-0.9.12-blue)
+![Version 1.0.0](https://img.shields.io/badge/version-1.0.0-blue)
 
 ![Jason, the JSON parsing horse](https://github.com/jasperhabicht/jsonparse/assets/6378801/ddfddc70-bf5f-4121-ba45-4b9128875d85)
 

Modified: trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex	2025-01-20 21:26:05 UTC (rev 73531)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex	2025-01-20 21:26:14 UTC (rev 73532)
@@ -11,8 +11,8 @@
 % This work has the LPPL maintenance status `maintained'.
 %
 \documentclass[a4paper]{article}
-\def\jsonparsefileversion{0.9.12}
-\def\jsonparsefiledate{17 January 2025}
+\def\jsonparsefileversion{1.0.0}
+\def\jsonparsefiledate{20 January 2025}
 
 \usepackage[T1]{fontenc}
 \usepackage{Alegreya}
@@ -212,6 +212,7 @@
 \changes{v0.9.10}{2024/12/10}{Enhanced backward compatibility; switching to linked property lists.}
 \changes{v0.9.11}{2025/01/15}{Bug fixes; adding additional command to loop over arrays.}
 \changes{v0.9.12}{2025/01/17}{Bug fixes; adding commands to access items in arrays.}
+\changes{v1.0.0}{2025/01/20}{Streamlining of code, unification of command structure.}
 
 \begin{document}
 \vspace*{-1cm}
@@ -288,7 +289,7 @@
 
 The naming of the relevant characters follows their Unicode names. However, \macro{hash} exists as alias for \macro{number sign}, \macro{dollar} as alias for \macro{dollar sign}, \macro{percent} for \macro{percent sign}, \macro{circumflex} for \macro{circumflex accent} and \macro{underscore} for \macro{low line}.
 
-This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayValues} and \macro{\JSONParseArrayValuesMap}.
+This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayItem}, \macro{\JSONParseArrayValues} as well as to the command \macro{\JSONParseArrayValuesMap}.
 
 \begin{macrodef}
 |rescan|
@@ -296,7 +297,7 @@
 \end{macrodef}
 The key \macro{rescan} can be used to activate and deactivate rescanning of the output. This key is active per default. Rescanning converts all tokens to their default category codes and TeX control sequences are expanded before typesetting. Further, during the rescanning process, JSON escape sequences are replaced and characters that don't require escaping in JSON but in TeX are replaced by the relevant TeX escape sequences.
 
-This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayValues} and \macro{\JSONParseArrayValuesMap}.
+This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayItem}, \macro{\JSONParseArrayValues} as well as to the command \macro{\JSONParseArrayValuesMap}.
 
 \section{Main user commands}
 
@@ -315,28 +316,6 @@
 The command \macro{\JSONParseFromFile} is used to parse a JSON file and store the parsed result in a token variable (a property list). It works the same way as \macro{\JSONParse}, but instead of a JSON string, it takes as third argument the path to the JSON file relative to the working directory.
 
 \begin{macrodef}
-|\JSONParseKeys|{<token variable>}{<key>}
-\end{macrodef}
-The command \macro{\JSONParseSetKeys} is used to return all top-level keys of a JSON object as JSON array. The first argument of the command takes the token variable that holds the parsed JSON data. The second argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. 
-
-\textbf{Caution!} This command has been redefined in version 0.9.12 which affects the accepted arguments and return value. 
-
-\begin{macrodef}
-|\JSONParseSetKeys|{<token variable>}{<token variable>}{<key>}
-\end{macrodef}
-The command \macro{\JSONParseSetKeys} is used to store all top-level keys of a JSON object as JSON array into a token variable. The second argument of the command takes the token variable that holds the parsed JSON data. The third argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. The first argument takes the token variable to hold the JSON array containing the top-level keys of the selected object. The token variable to store the keys as array is created if it does not exist.
-
-\begin{macrodef}
-|\JSONParseArrayItem|{<token variable>}{<index>}
-\end{macrodef}
-The command \macro{\JSONParseArrayItem} is used to return a single item from a JSON array using its index. The first argument expects a token variable that represents an JSON array as parsed JSON data. The second argument takes the index of the selected item of the array.
-
-\begin{macrodef}
-|\JSONParseSetArrayItem|{<token variable>}{<token variable>}{<index>}
-\end{macrodef}
-The command \macro{\JSONParseArrayItem} is used to store a single item from a JSON array using its index into a token variable. The second argument expects a token variable that represents an JSON array as parsed JSON data. The third argument takes the index of the selected item of the array. The first argument takes the token variable to hold the selected item from the array. The token variable to store the keys as array is created if it does not exist.
-
-\begin{macrodef}
 |\JSONParseValue|[<options>]{<token variable>}{<key>}
 \end{macrodef}
 The command \macro{\JSONParseValue} is used to select values from the token variable (property list) that has been created using the commands \macro{\JSONParse} or \macro{\JSONParseFromFile}. The second argument takes the token variable that holds the parsed JSON data. The third argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax.
@@ -347,7 +326,7 @@
 
 The first optional argument can be used to pass options to the command, such as \macro{escape} or \macro{rescan}, that are then applied locally. When the option \macro{rescan} is used, the token list is rescanned before it is typeset (which means that all category codes that may have been changed before are set to the default values). This is the default behaviour. If rescanning is not desired, pass the option \macro{rescan=false} to the command.
 
-When a key is associated with an object or array, the whole object or array is output as JSON string. The special key \macro{.} (or the string defined using the key \macro{child sep}) returns the whole JSON object as string.
+When a key is associated with an object or array, the whole object or array is output as JSON string. The special key \macro{.} (or the string defined using the key \macro{child sep}) returns the whole JSON object as string where all characters (except for spaces and tabs) have category code 12 (``other'').
 
 The command \macro{\JSONParseValue} is not expandable and can therefore not be used as argument of certain other arguments where expansion is needed. In such cases, the expandable command \macro{\JSONParseExpandableValue} should be used.
 
@@ -370,7 +349,7 @@
 \begin{macrodef}
 |\JSONParseSetRescanValue|{<token variable>}{<token variable>}{<key>}
 \end{macrodef}
-The command \macro{\JSONParseSetRescanValue} works the same way and also takes the same arguments as \macro{\JSONParseSetValue} except that it rescans the return value before storing it globally in the token variable. This means that the value stored in the token list will have the category codes TeX uses per default.
+The command \macro{\JSONParseSetRescanValue} works the same way and also takes the same arguments as \macro{\JSONParseSetValue} except that it rescans the return value before storing it globally in the token variable. This means that the value stored in the token list will have the category codes TeX uses per default. Option settings such as the \macro{escape} option are taken into consideration during the rescan process.
 
 This can, for example, be necessary when numbers stored in the JSON data in scientific format should be formatted using the \macro{siunitx} package. The rescan is needed here, because otherwise the character \macro{e} would have the wrong category code and would hence not be recognised by the formatting parser as exponent marker. Let us assume the key \macro{number} in some JSON source parsed into the token variable \macro{\myJSONnumber} represents the value \macro{-1.1e-1}, then the following could be used to format the output:
 
@@ -382,6 +361,18 @@
 \end{codeexamplecolumns}
 
 \begin{macrodef}
+|\JSONParseKeys|{<token variable>}{<key>}
+\end{macrodef}
+The command \macro{\JSONParseSetKeys} is used to get all top-level keys of a JSON object as JSON array and return this array as string where all characters (except for spaces and tabs) have category code 12 (``other''). The first argument of the command takes the token variable that holds the parsed JSON data. The second argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. 
+
+\textbf{Caution!} This command has been redefined in version 0.9.12 which affects the accepted arguments and return value.
+
+\begin{macrodef}
+|\JSONParseSetKeys|{<token variable>}{<token variable>}{<key>}
+\end{macrodef}
+The command \macro{\JSONParseSetKeys} is used to get all top-level keys of a JSON object as JSON array and parse this array into a token variable (a property list). The second argument of the command takes the token variable that holds the parsed JSON data. The third argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. The first argument takes the token variable to hold the JSON array containing the top-level keys of the selected object. The token variable to store the keys as array is created if it does not exist.
+
+\begin{macrodef}
 |\JSONParseArrayValues|[<options>]{<token variable>}{<key>}[<subkey>]{<string>}
 \end{macrodef}
 The command \macro{\JSONParseArrayValues} is used to select all values from an array from a parsed JSON string or JSON file. The second argument takes the token variable that holds the parsed JSON data. The first argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. The third argument is optional and can be used to pass a subkey, i.\,e. a key that is used to select a value for every item. The last argument takes a string that is inserted between all values when they are typeset.
@@ -490,7 +481,7 @@
 \end{itemize}
 \end{codeexamplecolumns}
 
-Making use of the commands \macro{\JSONParseSetKeys} and \macro{\JSONParseArrayItem}, keys and values can be accessed. Due to the fact that cells create scopes, we need to repeat the part of the code that selects the current key:
+Making use of the commands \macro{\JSONParseSetKeys} and \macro{\JSONParseSetValue}, keys and values can be accessed. Due to the fact that cells create scopes, we need to repeat the part of the code that selects the current key:
 
 \begin{codeexamplecolumns}
 \JSONParseArrayMapInline{\myJSONdata}
@@ -497,10 +488,10 @@
   {array}{
   \JSONParseSetKeys{\mykeys}{\myJSONdata}
     {array[#1]}
-  \JSONParseSetArrayItem{\mykeya}
-    {\mykeys}{0}
-  \JSONParseSetArrayItem{\mykeyb}
-    {\mykeys}{1}
+  \JSONParseSetValue{\mykeya}
+    {\mykeys}{[0]}
+  \JSONParseSetValue{\mykeyb}
+    {\mykeys}{[1]}
 
   \emph{\mykeya :}
   \JSONParseValue{\myJSONdata}
@@ -578,7 +569,7 @@
 \end{macrodef}
 If set (or explicitly set to \macro{true}), the key \macro{zero-based} sets the numbering of the index of array items to zero-based. If set to false, the indexing starts with one instead. Per default, the package uses zero-based indexing to resemble JavaScript notation.
 
-This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. 
+This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}.
 
 \begin{macrodef}
 replace/|true|={<string>}
@@ -598,7 +589,8 @@
 \end{macrodef}
 These keys can be used to set the replacement text for the JSON escape sequences \macro{\b} (backspace), \macro{\f} (formfeed), \macro{\n} (linefeed), \macro{\r} (carriage return) and \macro{\t} (horizontal tab). The default replacement string is a space. Only strings can be used as replacement. These replacements take place only during typesetting.
 
-These keys can be set using \macro{\JSONParseSet}. They can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayValues} and \macro{\JSONParseArrayValuesMap}.
+These keys can be set using \macro{\JSONParseSet}. They can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayItem}, \macro{\JSONParseArrayValues} as well as to the command \macro{\JSONParseArrayValuesMap}.
+
 \begin{macrodef}
 |check num|
 |check num|={<boolean>}

Modified: trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty	2025-01-20 21:26:05 UTC (rev 73531)
+++ trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty	2025-01-20 21:26:14 UTC (rev 73532)
@@ -10,7 +10,7 @@
 %
 % This work has the LPPL maintenance status `maintained'.
 %
-\ProvidesExplPackage {jsonparse} {2025-01-17} {0.9.12}
+\ProvidesExplPackage {jsonparse} {2025-01-20} {1.0.0}
   {A handy way to parse, store and access JSON data from files or strings in LaTeX documents}
 
 \msg_new:nnn { jsonparse } { old-kernel } {
@@ -70,6 +70,16 @@
   Escape ~ character ~ #1 ~ not ~ found.
 }
 
+\msg_new:nnn { jsonparse } { prop-undefined } {
+  \msg_error_text:n { jsonparse } \iow_newline:
+  Property ~ list ~ undefined: ~ #1.
+}
+
+\msg_new:nnn { jsonparse } { cs-undefined } {
+  \msg_error_text:n { jsonparse } \iow_newline:
+  Control ~ sequence ~ undefined: ~ #1.
+}
+
 \msg_new:nnn { jsonparse } { unknown-key } {
   \msg_warning_text:n { jsonparse } \iow_newline:
   Ignoring ~ unknown ~ key: ~ #1.
@@ -310,6 +320,7 @@
 \tl_new:N \g__jsonparse_json_tl
 \tl_new:N \l__jsonparse_input_tl
 \tl_new:N \l__jsonparse_temp_tl
+\tl_new:N \l__jsonparse_keys_tl
 \tl_new:N \l__jsonparse_keys_array_tl
 \tl_new:N \l__jsonparse_prefix_tl
 \tl_new:N \l__jsonparse_key_tl
@@ -676,7 +687,11 @@
     \bool_if:NT \l__jsonparse_zero_based_bool {
       \int_decr:N \l__jsonparse_array_index_int
     }
-    \tl_set_eq:NN \l__jsonparse_object_array_key_tl \l__jsonparse_key_tl
+    \tl_if_empty:NTF \l__jsonparse_key_tl {
+      \tl_set_eq:NN \l__jsonparse_object_array_key_tl \l__jsonparse_child_sep_str
+    } {
+      \tl_set_eq:NN \l__jsonparse_object_array_key_tl \l__jsonparse_key_tl
+    }
     \tl_set:Nn \l__jsonparse_object_array_val_tl { [ #1 }
     \tl_set:Ne \l__jsonparse_prefix_tl { \l__jsonparse_key_tl \l__jsonparse_array_sep_left_str }
     \__jsonparse_parse_remainder:
@@ -1052,11 +1067,32 @@
 }
 \cs_generate_variant:Nn \__jsonparse_gset_rescan:Nn { Ne }
 
+\cs_new:Npn \__jsonparse_warning_undefined_prop:N #1 {
+  \prop_if_exist:NF #1 {
+    \msg_error:nnn { jsonparse } { prop-undefined }
+      {#1}
+  }
+}
+
+\NewDocumentCommand { \JSONParseValue } { O{} m m } {
+  \__jsonparse_warning_undefined_prop:N #2
+  \group_begin:
+    \keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist
+    \__jsonparse_warning_unused_keys:
+    \bool_if:NTF \l__jsonparse_rescan_bool {
+      \exp_args:Ne \__jsonparse_rescan:n { \prop_item:Ne #2 {#3} }
+    } {
+      \prop_item:Ne #2 {#3}
+    }
+  \group_end:
+}
+
 \NewExpandableDocumentCommand { \JSONParseExpandableValue } { m m } {
   \prop_item:Ne #1 {#2}
 }
 
 \NewDocumentCommand { \JSONParseSetValue } { m m m } {
+  \__jsonparse_warning_undefined_prop:N #2
   \tl_if_exist:NF #1 {
     \tl_new:N #1
   }
@@ -1064,6 +1100,7 @@
 }
 
 \NewDocumentCommand { \JSONParseSetRescanValue } { m m m } {
+  \__jsonparse_warning_undefined_prop:N #2
   \tl_if_exist:NF #1 {
     \tl_new:N #1
   }
@@ -1070,19 +1107,14 @@
   \__jsonparse_gset_rescan:Ne #1 { \prop_item:Ne #2 {#3} }
 }
 
-\NewDocumentCommand { \JSONParseValue } { O{} m m } {
-  \group_begin:
-    \keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist
-    \__jsonparse_warning_unused_keys:
-    \bool_if:NTF \l__jsonparse_rescan_bool {
-      \exp_args:Ne \__jsonparse_rescan:n { \prop_item:Ne #2 {#3} }
-    } {
-      \prop_item:Ne #2 {#3}
-    }
-  \group_end:
+\cs_new:Npn \__jsonparse_parse_keys:NN #1#2 {
+  \tl_set:Nn \l__jsonparse_keys_array_tl { [ }
+  \prop_map_function:NN #1 \__jsonparse_parse_keys_aux:nn
+  \tl_put_right:Nn \l__jsonparse_keys_array_tl { ] }
+  \tl_set_eq:NN #2 \l__jsonparse_keys_array_tl
 }
 
-\cs_new:Npn \__jsonparse_keys:n #1#2 {
+\cs_new:Npn \__jsonparse_parse_keys_aux:nn #1#2 {
   \tl_if_in:nVF {#1} \l__jsonparse_child_sep_str {
     \bool_if:NTF \l__jsonparse_prop_map_first_bool {
       \bool_set_false:N \l__jsonparse_prop_map_first_bool
@@ -1094,18 +1126,18 @@
 }
 
 \NewDocumentCommand { \JSONParseKeys } { m m } {
+  \__jsonparse_warning_undefined_prop:N #1
   \group_begin:
     \tl_set_eq:NN \l__jsonparse_temp_tl #1
     \jsonparse_filter:Nn \l__jsonparse_temp_tl {#2}
     \bool_set_true:N \l__jsonparse_prop_map_first_bool
-    \tl_set:Nn \l__jsonparse_keys_array_tl { [ }
-    \prop_map_function:NN \l__jsonparse_temp_tl \__jsonparse_keys:n
-    \tl_put_right:Nn \l__jsonparse_keys_array_tl { ] }
-    \tl_use:N \l__jsonparse_keys_array_tl
+    \__jsonparse_parse_keys:NN \l__jsonparse_temp_tl \l__jsonparse_keys_tl
+    \tl_use:N \l__jsonparse_keys_tl
   \group_end:
 }
 
 \NewDocumentCommand { \JSONParseSetKeys } { m m m } {
+  \__jsonparse_warning_undefined_prop:N #2
   \tl_if_exist:NF #1 {
     \tl_new:N #1
   }
@@ -1113,32 +1145,12 @@
     \tl_set_eq:NN \l__jsonparse_temp_tl #2
     \jsonparse_filter:Nn \l__jsonparse_temp_tl {#3}
     \bool_set_true:N \l__jsonparse_prop_map_first_bool
-    \tl_set:Nn \l__jsonparse_keys_array_tl { [ }
-    \prop_map_function:NN \l__jsonparse_temp_tl \__jsonparse_keys:n
-    \tl_put_right:Nn \l__jsonparse_keys_array_tl { ] }
+    \__jsonparse_parse_keys:NN \l__jsonparse_temp_tl \l__jsonparse_keys_tl
     \exp_last_unbraced:Nf
   \group_end:
-  \tl_set:NV #1 \l__jsonparse_keys_array_tl
+  \exp_args:NNe \jsonparse_parse_to_prop:Nn #1 { \l__jsonparse_keys_tl }
 }
 
-\NewDocumentCommand { \JSONParseArrayItem } { m m } {
-  \group_begin:
-    \exp_args:NNe \jsonparse_parse_to_prop:Nn \l__jsonparse_temp_tl { #1 }
-    \prop_item:Nn \l__jsonparse_temp_tl { [ #2 ] }
-  \group_end:
-}
-
-\NewDocumentCommand { \JSONParseSetArrayItem } { m m m } {
-  \tl_if_exist:NF #1 {
-    \tl_new:N #1
-  }
-  \group_begin:
-    \exp_args:NNe \jsonparse_parse_to_prop:Nn \l__jsonparse_temp_tl { #2 }
-    \exp_last_unbraced:Nf
-  \group_end:
-  \tl_set:Ne #1 { \prop_item:Nn \l__jsonparse_temp_tl { [ #3 ] } }
-}
-
 \cs_new:Npn \__jsonparse_get_array_index:w [ #1 ] #2 \q_stop {
   #1
 }
@@ -1166,6 +1178,7 @@
 }
 
 \NewDocumentCommand { \JSONParseArrayCount } { m m } {
+  \__jsonparse_warning_undefined_prop:N #1
   \group_begin:
     \tl_set_eq:NN \l__jsonparse_temp_tl #1
     \jsonparse_filter:Nn \l__jsonparse_temp_tl {#2}
@@ -1175,6 +1188,7 @@
 }
 
 \NewDocumentCommand { \JSONParseSetArrayCount } { m m m } {
+  \__jsonparse_warning_undefined_prop:N #2
   \tl_if_exist:NF #1 {
     \tl_new:N #1
   }
@@ -1227,6 +1241,7 @@
 }
 
 \NewDocumentCommand { \JSONParseArrayValues } { O{} m m O{} m } {
+  \__jsonparse_warning_undefined_prop:N #2
   \group_begin:
     \keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist
     \__jsonparse_warning_unused_keys:
@@ -1337,6 +1352,11 @@
 }
 
 \NewDocumentCommand { \JSONParseArrayValuesMap } { O{} m m O{} m O{} O{} } {
+  \__jsonparse_warning_undefined_prop:N #2
+  \cs_if_exist:cF {#5} {
+    \msg_error:nne { jsonparse } { cs-undefined }
+      { \c_backslash_str #5 }
+  }
   \group_begin:
     \keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist
     \__jsonparse_warning_unused_keys:
@@ -1360,6 +1380,7 @@
 \cs_new:Npn \__jsonparse_array_map_inline:n #1 { }
 
 \NewDocumentCommand { \JSONParseArrayMapInline } { m m +m } {
+  \__jsonparse_warning_undefined_prop:N #1
   \cs_gset:Npn \__jsonparse_array_map_inline:n ##1 {#3}
   \group_begin:
     \tl_set_eq:NN \l__jsonparse_temp_tl #1



More information about the tex-live-commits mailing list.