texlive[73004] Master/texmf-dist: jsonparse (30nov24)

commits+karl at tug.org commits+karl at tug.org
Sat Nov 30 22:12:19 CET 2024


Revision: 73004
          https://tug.org/svn/texlive?view=revision&revision=73004
Author:   karl
Date:     2024-11-30 22:12:19 +0100 (Sat, 30 Nov 2024)
Log Message:
-----------
jsonparse (30nov24)

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	2024-11-30 21:12:06 UTC (rev 73003)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/README.md	2024-11-30 21:12:19 UTC (rev 73004)
@@ -1,4 +1,4 @@
-![Version 0.9.7](https://img.shields.io/badge/version-0.9.7-blue)
+![Version 0.9.8](https://img.shields.io/badge/version-0.9.8-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	2024-11-30 21:12:06 UTC (rev 73003)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex	2024-11-30 21:12:19 UTC (rev 73004)
@@ -11,8 +11,8 @@
 % This work has the LPPL maintenance status `maintained'.
 % 
 \documentclass[a4paper]{article}
-\def\jsonparsefileversion{0.9.7}
-\def\jsonparsefiledate{5 November 2024}
+\def\jsonparsefileversion{0.9.8}
+\def\jsonparsefiledate{30 November 2024}
 
 \usepackage[T1]{fontenc}
 \usepackage{Alegreya}
@@ -19,7 +19,7 @@
 \usepackage{AlegreyaSans}
 \usepackage{FiraMono}
 
-\usepackage{geometry, longtable, booktabs, tcolorbox, hyperref}
+\usepackage{geometry, longtable, booktabs, siunitx, tcolorbox, hyperref}
 \geometry{margin=25mm, left=45mm}
 
 \usepackage{fancyhdr}
@@ -206,6 +206,7 @@
 \changes{v0.9.5}{2024/10/27}{Streamlining of code, clarification of explanations in documentation.}
 \changes{v0.9.6}{2024/10/31}{Allowing for multiple return values when mapping over arrays.}
 \changes{v0.9.7}{2024/11/05}{Streamlining of code, ensuring backward compatibility.}
+\changes{v0.9.8}{2024/11/19}{Bug fixes, adding possibility to store value in token list.}
 
 \begin{document}
 \vspace*{-1cm}
@@ -316,7 +317,7 @@
 \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 first argument 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.
+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.
 
 If the JSON string \macro{{ "key" : "value" }} is parsed into the token variable \macro{\myJSONdata}, using \macro{\JSONParseValue{\myJSONdata}{key}} would extract the value associated with the key \macro{key}, which in this case is \macro{value}, and typeset it to the document.
 
@@ -336,9 +337,32 @@
 For example, if the JSON string \macro{{ "key" : "value" }} has been parsed into the token variable \macro{\myJSONdata}, the command \macro{\JSONParseExpandableValue{\myJSONdata}{key}} will expand to the exact same token list as \macro{\detokenize{value}} with all characters having category code 12 (``other''). 
 
 \begin{macrodef}
+|\JSONParseSetValue|{<token variable>}{<token variable>}{<key>}
+\end{macrodef}
+The expandable command \macro{\JSONParseValueSet} can be used to a select a value from the token variable that stores the parsed JSON data via a key and store this value in another token variable. 
+
+The first argument denotes the token variable where the value should be stored into. If this token variable has not yet been defined, it will be created by this command. The second argument represents the token variable (property list) that has been created using the commands \macro{\JSONParse} or \macro{\JSONParseFromFile} and that stores the parsed JSON data. The third argument takes the key to select the relevant value.
+
+The token list returned by this command is a string variable where all characters have category code 12 (``other''), except for spaces and (horizontal) tabs that have category code 10 (``space'').
+
+\begin{macrodef}
+|\JSONParseSetRescanValue|{<token variable>}{<token variable>}{<key>}
+\end{macrodef}
+The expandable 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 in the token variable. This means that the value stored in the token list will have the category codes TeX uses per default.
+
+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:
+
+\JSONParse{\myJSONnumber}{ { "number" : -1.1e-1 } }
+\begin{codeexamplecolumns}
+\JSONParseSetRescanValue{\mynumber}
+  {\myJSONnumber}{number}
+\num{\mynumber}
+\end{codeexamplecolumns}
+
+\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 first argument 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. 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.
+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.
 
 For example, let us assume the following JSON data structure is parsed into the token variable \macro{\myJSONdata}:
 

Modified: trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty	2024-11-30 21:12:06 UTC (rev 73003)
+++ trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty	2024-11-30 21:12:19 UTC (rev 73004)
@@ -10,14 +10,15 @@
 %
 % This work has the LPPL maintenance status `maintained'.
 %
-\ProvidesExplPackage {jsonparse} {2024-11-05} {0.9.7}
+\ProvidesExplPackage {jsonparse} {2024-11-30} {0.9.8}
   {A handy way to parse, store and access JSON data from files or strings in LaTeX documents}
 
 \bool_new:N \l__jsonparse_debug_mode_bool
+
 \keys_define:nn { jsonparse / global } {
-  debug .bool_set:N = \l__jsonparse_debug_mode_bool ,
-  debug .default:n  = { true } ,
-  debug .initial:n  = { false }
+  debug   .bool_set:N = \l__jsonparse_debug_mode_bool ,
+  debug   .default:n  = { true } ,
+  debug   .initial:n  = { false } 
 }
 \ProcessKeyOptions [ jsonparse / global ]
 
@@ -330,14 +331,21 @@
   0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
 }
 
-\clist_const:Ne \c__jsonparse_num_others_clist {
+\clist_const:Ne \c__jsonparse_num_plus_minus_fraction_clist {
   \tl_to_str:n { + } ,
   \tl_to_str:n { - } ,
-  \tl_to_str:n { . } ,
+  \tl_to_str:n { . }
+}
+
+\clist_const:Ne \c__jsonparse_num_exponent_clist {
   \tl_to_str:n { e } ,
   \tl_to_str:n { E }
 }
 
+\clist_concat:NNN \c__jsonparse_num_others_clist 
+  \c__jsonparse_num_plus_minus_fraction_clist
+  \c__jsonparse_num_exponent_clist
+
 \prg_new_conditional:Npnn \jsonparse_if_num:n #1 { p , T , F , TF } {
   \bool_set_true:N \l__jsonparse_num_bool
   \bool_set_false:N \l__jsonparse_num_zero_seen_bool
@@ -415,7 +423,7 @@
         \bool_set_false:N \l__jsonparse_num_bool
       }
     } {
-      \clist_if_in:NVT \c__jsonparse_num_others_clist \l__jsonparse_num_input_last_tl {
+      \clist_if_in:NVT \c__jsonparse_num_plus_minus_fraction_clist \l__jsonparse_num_input_last_tl {
         \tl_set:Nn \l__jsonparse_num_remainder_tl { }
         \bool_set_false:N \l__jsonparse_num_bool
       }
@@ -940,10 +948,6 @@
   \group_end:
 }
 
-\NewExpandableDocumentCommand { \JSONParseExpandableValue } { m m } {
-  \prop_item:Ne #1 {#2}
-}
-
 \cs_set_eq:NN \__jsonparse_tex_quote: \"
 \cs_set_eq:NN \__jsonparse_tex_backslash: \\
 
@@ -990,6 +994,24 @@
   \group_end:
 }
 
+\NewExpandableDocumentCommand { \JSONParseExpandableValue } { m m } {
+  \prop_item:Ne #1 {#2}
+}
+
+\NewExpandableDocumentCommand { \JSONParseSetValue } { m m m } {
+  \tl_if_exist:NF #1 {
+    \tl_new:N #1
+  }
+  \tl_set:Nne #1 { \prop_item:Ne #2 {#3} }
+}
+
+\NewExpandableDocumentCommand { \JSONParseSetRescanValue } { m m m } {
+  \tl_if_exist:NF #1 {
+    \tl_new:N #1
+  }
+  \tl_set_rescan:Nne #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
@@ -1195,7 +1217,7 @@
   \use:c { \l__jsonparse_array_map_function_str }
 }
 
-\cs_set:Npn \__jsonparse_array_map_create_cs:n #1 {
+\cs_set:Npn \__jsonparse_array_map_generate_cs:n #1 {
   \int_incr:N \l__jsonparse_array_keys_index_int
   \tl_set:Ne \l__jsonparse_array_keys_index_roman_tl {
     \int_to_Roman:n { \l__jsonparse_array_keys_index_int }
@@ -1220,7 +1242,7 @@
     \clist_if_empty:NF \l__jsonparse_array_map_keys_clist {
       \int_zero:N \l__jsonparse_array_keys_index_int
       \clist_map_function:NN \l__jsonparse_array_map_keys_clist
-        \__jsonparse_array_map_create_cs:n
+        \__jsonparse_array_map_generate_cs:n
     }
     #6
     \int_step_function:nN { \l__jsonparse_array_count_int } 
@@ -1229,4 +1251,4 @@
   \group_end:
 }
 
-% EOF
+% ===



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