texlive[73488] Master/texmf-dist: jsonparse (17jan25)

commits+karl at tug.org commits+karl at tug.org
Fri Jan 17 21:19:42 CET 2025


Revision: 73488
          https://tug.org/svn/texlive?view=revision&revision=73488
Author:   karl
Date:     2025-01-17 21:19:42 +0100 (Fri, 17 Jan 2025)
Log Message:
-----------
jsonparse (17jan25)

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-17 20:19:33 UTC (rev 73487)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/README.md	2025-01-17 20:19:42 UTC (rev 73488)
@@ -1,4 +1,4 @@
-![Version 0.9.11](https://img.shields.io/badge/version-0.9.11-blue)
+![Version 0.9.12](https://img.shields.io/badge/version-0.9.12-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-17 20:19:33 UTC (rev 73487)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex	2025-01-17 20:19:42 UTC (rev 73488)
@@ -11,8 +11,8 @@
 % This work has the LPPL maintenance status `maintained'.
 %
 \documentclass[a4paper]{article}
-\def\jsonparsefileversion{0.9.11}
-\def\jsonparsefiledate{15 January 2025}
+\def\jsonparsefileversion{0.9.12}
+\def\jsonparsefiledate{17 January 2025}
 
 \usepackage[T1]{fontenc}
 \usepackage{Alegreya}
@@ -211,6 +211,7 @@
 \changes{v0.9.8}{2024/11/19}{Bug fixes; adding possibility to store value in token list.}
 \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.}
 
 \begin{document}
 \vspace*{-1cm}
@@ -314,11 +315,28 @@
 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>}{<token variable>}
+|\JSONParseKeys|{<token variable>}{<key>}
 \end{macrodef}
-The command \macro{\JSONParseKeys} is used to store all top-level keys of a parsed JSON object as array into a token variable. The command takes as first argument the token variable that holds the parsed JSON data. The second argument takes the token variable that is assigned a JSON array containing the top-level keys of the object represented by the token variable in the first argument. The token variable to store the keys as array is created if it does not exist.
+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.
@@ -472,6 +490,30 @@
 \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:
+
+\begin{codeexamplecolumns}
+\JSONParseArrayMapInline{\myJSONdata}
+  {array}{
+  \JSONParseSetKeys{\mykeys}{\myJSONdata}
+    {array[#1]}
+  \JSONParseSetArrayItem{\mykeya}
+    {\mykeys}{0}
+  \JSONParseSetArrayItem{\mykeyb}
+    {\mykeys}{1}
+
+  \emph{\mykeya :}
+  \JSONParseValue{\myJSONdata}
+    {array[#1].\mykeya}\par
+
+  \emph{\mykeyb :}
+  \JSONParseValue{\myJSONdata}
+    {array[#1].\mykeyb}\par\bigskip
+}
+\end{codeexamplecolumns}
+
+Note that the underscores in the names of the keys can be printed without changing to math mode in the above example because all JSON data is stored as string where all characters (except for spaces and tabs) have category code 12 (``other'').
+
 \subsection{Externalising parsed JSON data}\label{sec:externalizing}
 
 Parsing large JSON files can take quite a while. In order to speed up follow-up compilation runs, this package provides a way to store parsed JSON data for future use. Once a file for externalization has been created, the package will try to load the data from this file instead of parsing the JSON data again.

Modified: trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty	2025-01-17 20:19:33 UTC (rev 73487)
+++ trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty	2025-01-17 20:19:42 UTC (rev 73488)
@@ -10,7 +10,7 @@
 %
 % This work has the LPPL maintenance status `maintained'.
 %
-\ProvidesExplPackage {jsonparse} {2025-01-15} {0.9.11}
+\ProvidesExplPackage {jsonparse} {2025-01-17} {0.9.12}
   {A handy way to parse, store and access JSON data from files or strings in LaTeX documents}
 
 \msg_new:nnn { jsonparse } { old-kernel } {
@@ -262,7 +262,7 @@
 \cs_generate_variant:Nn \str_casefold:n { o }
 \cs_generate_variant:Nn \str_head_ignore_spaces:n { o }
 \cs_generate_variant:Nn \str_set:Nn { Ne }
-\cs_generate_variant:Nn \int_step_inline:nnn { nVn }
+\cs_generate_variant:Nn \int_step_function:nnN { nVN }
 \cs_generate_variant:Nn \clist_const:Nn { Ne }
 \cs_generate_variant:Nn \seq_put_right:Nn { Ne }
 \cs_generate_variant:Nn \prop_gput:Nnn { Nee }
@@ -310,6 +310,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_array_tl
 \tl_new:N \l__jsonparse_prefix_tl
 \tl_new:N \l__jsonparse_key_tl
 \tl_new:N \l__jsonparse_val_tl
@@ -1081,28 +1082,63 @@
   \group_end:
 }
 
-\cs_new:Npn \__jsonparse_keys:n #1 {
+\cs_new:Npn \__jsonparse_keys:n #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
     } {
-      \tl_put_right:Nn \l__jsonparse_temp_tl { , }
+      \tl_put_right:Nn \l__jsonparse_keys_array_tl { , }
     }
-    \tl_put_right:Nn \l__jsonparse_temp_tl { " #1 " }
+    \tl_put_right:Nn \l__jsonparse_keys_array_tl { " #1 " }
   }
 }
 
 \NewDocumentCommand { \JSONParseKeys } { m m } {
-  \tl_if_exist:NF #2 {
-    \tl_new:N #2
+  \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
+  \group_end:
+}
+
+\NewDocumentCommand { \JSONParseSetKeys } { m m m } {
+  \tl_if_exist:NF #1 {
+    \tl_new:N #1
   }
-  \bool_set_true:N \l__jsonparse_prop_map_first_bool
-  \tl_set:Nn \l__jsonparse_temp_tl { [ }
-  \prop_map_function:NN #1 \__jsonparse_keys:n
-  \tl_put_right:Nn \l__jsonparse_temp_tl { ] }
-  \tl_set_eq:NN #2 \l__jsonparse_temp_tl
+  \group_begin:
+    \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 { ] }
+    \exp_last_unbraced:Nf
+  \group_end:
+  \tl_set:NV #1 \l__jsonparse_keys_array_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
 }
@@ -1321,7 +1357,10 @@
   \group_end:
 }
 
-\NewDocumentCommand { \JSONParseArrayMapInline } { m m m } {
+\cs_new:Npn \__jsonparse_array_map_inline:n #1 { }
+
+\NewDocumentCommand { \JSONParseArrayMapInline } { m m +m } {
+  \cs_gset:Npn \__jsonparse_array_map_inline:n ##1 {#3}
   \group_begin:
     \tl_set_eq:NN \l__jsonparse_temp_tl #1
     \jsonparse_filter:Nn \l__jsonparse_temp_tl {#2}
@@ -1331,9 +1370,9 @@
     }
     \exp_last_unbraced:Nf
   \group_end:
-  \int_step_inline:nVn {
+  \int_step_function:nVN {
     \bool_if:NTF \l__jsonparse_zero_based_bool { 0 } { 1 }
-  } \l__jsonparse_array_count_int {#3}
+  } \l__jsonparse_array_count_int \__jsonparse_array_map_inline:n
 }
 
 % ===



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