texlive[73712] Master/texmf-dist: jsonparse (3feb25)
commits+karl at tug.org
commits+karl at tug.org
Mon Feb 3 21:54:21 CET 2025
Revision: 73712
https://tug.org/svn/texlive?view=revision&revision=73712
Author: karl
Date: 2025-02-03 21:54:21 +0100 (Mon, 03 Feb 2025)
Log Message:
-----------
jsonparse (3feb25)
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-02-03 20:54:11 UTC (rev 73711)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/README.md 2025-02-03 20:54:21 UTC (rev 73712)
@@ -1,4 +1,4 @@
-
+

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-02-03 20:54:11 UTC (rev 73711)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex 2025-02-03 20:54:21 UTC (rev 73712)
@@ -11,8 +11,8 @@
% This work has the LPPL maintenance status `maintained'.
%
\documentclass[a4paper]{article}
-\def\jsonparsefileversion{1.1.0}
-\def\jsonparsefiledate{30 January 2025}
+\def\jsonparsefileversion{1.1.1}
+\def\jsonparsefiledate{3 February 2025}
\usepackage[T1]{fontenc}
\usepackage{Alegreya}
@@ -22,6 +22,9 @@
\usepackage{geometry, longtable, booktabs, siunitx, tcolorbox, hyperref}
\geometry{margin=25mm, left=45mm}
+\usepackage{pgfplots}
+\pgfplotsset{compat=1.18}
+
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
@@ -229,6 +232,7 @@
\changes{v1.0.2}{2025/01/23}{Support for Unicode surrogate pairs.}
\changes{v1.0.3}{2025/01/26}{Test for valid JSON numbers expandable.}
\changes{v1.1.0}{2025/01/30}{Unified names of user functions; renaming key for keywords.}
+\changes{v1.1.1}{2025/02/03}{Added option to store result of mapped inline function.}
\begin{document}
\vspace*{-1cm}
@@ -504,9 +508,9 @@
For reasons of backward compatibility, the command \macro{\JSONParseArrayValuesMap} is defined as alias of \macro{\JSONParseArrayMapFunction}.
\begin{macrodef}
-|\JSONParseArrayMapInline|{<token variable>}{<key>}{<inline function>}
+|\JSONParseArrayMapInline|[<options>]{<token variable>}{<key>}{<inline function>}
\end{macrodef}
-The command \macro{\JSONParseArrayMapInline} takes as first argument a token variable holding a parsed JSON string or JSON file and as second argument a key to select an array in the JSON data. The third parameter can contain any code where the index of the current item is represented by \macro{#1}.
+The command \macro{\JSONParseArrayMapInline} takes as first mandatory argument a token variable holding a parsed JSON string or JSON file and as second mandatory argument a key to select an array in the JSON data. The last argument can contain any code where the index of the current item is represented by \macro{#1}.
Using the above example, the mechanism could be implemented as follows:
@@ -544,6 +548,38 @@
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'').
+\begin{macrodef}
+|store in|={<token variable>}
+\end{macrodef}
+
+The command \macro{\JSONParseArrayMapInline} accepts as option set in the optional argument the key \macro{store in} which takes a token variable into which the result of the mapped inline function should be stored. It is important to note that the inline function needs to be fully expandable. For example, it is not possible to use \macro{\JSONParseValue} in the code of the inline function while \macro{\JSONParseExpandableValue} is allowed.
+
+Storing the result of the mapped inline function can be helpful if JSON data should be reformatted for use in a plotting functions. An example for a use case with PGFplots is shown below. In this example, the parsed JSON string \macro{{ "data": [ [0,0], [1,-1], [2,1] ] }} was stored in the token variable \macro{\myJSONplotdata}.
+
+\JSONParse{\myJSONplotdata}{ { "data": [ [0,0], [1,-1], [2,1] ] } }
+\pgfplotsset{width=5.25cm}
+
+\begin{codeexamplecolumns}
+\JSONParseArrayMapInline
+[store in={\myJSONplotcoords}]
+ {\myJSONplotdata}{data}{
+ (
+ \JSONParseExpandableValue
+ {\myJSONplotdata}{data[#1][0]}
+ ,
+ \JSONParseExpandableValue
+ {\myJSONplotdata}{data[#1][1]}
+ )
+}
+
+\begin{tikzpicture}
+ \begin{axis}
+ \addplot coordinates
+ {\myJSONplotcoords};
+ \end{axis}
+\end{tikzpicture}
+\end{codeexamplecolumns}
+
\subsection{Externalizing parsed JSON data}\label{sec:externalizing}
Parsing large and complex 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.
@@ -628,7 +664,7 @@
\subsubsection{Keys affecting the typesetting}
-Information about the keys \macro{escape} and \macro{rescan} can be found above in section \ref{sec:escaping}. Information about the keys \macro{code before} and \macro{code after} can be found above in the description to the command \macro{\JSONParseArrayMapFunction}.
+Information about the keys \macro{escape} and \macro{rescan} can be found above in section \ref{sec:escaping}. Information about the keys \macro{code before} and \macro{code after} can be found above in the description to the command \macro{\JSONParseArrayMapFunction}. Information about the key \macro{store in} can be found above in the description to the command \macro{\JSONParseArrayMapInline}.
\begin{macrodef}
keyword/|true|={<string>}
Modified: trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty 2025-02-03 20:54:11 UTC (rev 73711)
+++ trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty 2025-02-03 20:54:21 UTC (rev 73712)
@@ -10,7 +10,7 @@
%
% This work has the LPPL maintenance status `maintained'.
%
-\ProvidesExplPackage {jsonparse} {2025-01-30} {1.1.0}
+\ProvidesExplPackage {jsonparse} {2025-02-03} {1.1.1}
{A handy way to parse, store and access JSON data from files or strings in LaTeX documents}
\msg_new:nnn { jsonparse } { old-kernel } {
@@ -46,7 +46,8 @@
\msg_new:nnn { jsonparse } { nested-non-expandable } {
\msg_error_text:n { jsonparse } \iow_newline:
- Nested ~ use ~ of ~ \token_to_str:N \JSONParseValue \c_space_tl not ~ allowed. \iow_newline:
+ Non-expandable ~ commands ~ such ~ as ~ \token_to_str:N \JSONParseValue \c_space_tl
+ not ~ allowed ~ in ~ inline ~ function. \iow_newline:
Use ~ \token_to_str:N \JSONParseExpandableValue \c_space_tl instead.
}
@@ -125,8 +126,9 @@
\str_new:N \l__jsonparse_carriage_return_str
\str_new:N \l__jsonparse_horizontal_tab_str
-\tl_new:N \l__jsonparse_map_before_tl
-\tl_new:N \l__jsonparse_map_after_tl
+\tl_new:N \l__jsonparse_array_map_code_before_tl
+\tl_new:N \l__jsonparse_array_map_code_after_tl
+\tl_new:N \g__jsonparse_array_map_store_in_tl
\clist_new:N \l__jsonparse_unused_keys_clist
@@ -237,10 +239,14 @@
rescan .default:n = { true } ,
rescan .initial:n = { true } ,
rescan .groups:n = { output } ,
- code ~ before .tl_set:N = \l__jsonparse_map_before_tl ,
- code ~ after .tl_set:N = \l__jsonparse_map_after_tl
+ code ~ before .tl_set:N = \l__jsonparse_array_map_code_before_tl ,
+ code ~ after .tl_set:N = \l__jsonparse_array_map_code_after_tl
}
+\keys_define:nn { jsonparse / map } {
+ store ~ in .tl_gset:N = \g__jsonparse_array_map_store_in_tl
+}
+
\cs_new_protected:Npn \__jsonparse_warning_unused_keys: {
\clist_map_inline:Nn \l__jsonparse_unused_keys_clist {
\msg_warning:nne { jsonparse } { unknown-key } {
@@ -253,6 +259,7 @@
\keys_set_known:nnN { jsonparse / global } {#1} \l__jsonparse_unused_keys_clist
\keys_set_known:noN { jsonparse / parse } { \l__jsonparse_unused_keys_clist } \l__jsonparse_unused_keys_clist
\keys_set_known:noN { jsonparse / typeset } { \l__jsonparse_unused_keys_clist } \l__jsonparse_unused_keys_clist
+ \keys_set_known:noN { jsonparse / map } { \l__jsonparse_unused_keys_clist } \l__jsonparse_unused_keys_clist
\__jsonparse_warning_unused_keys:
}
@@ -263,6 +270,8 @@
\cs_new:Npn \str_foldcase:n { \str_casefold:n }
}
+\exp_args_generate:n { NoV }
+
\cs_generate_variant:Nn \file_input:n { e }
\cs_generate_variant:Nn \tl_gset:Nn { Ne , ce }
\cs_generate_variant:Nn \tl_gset_rescan:Nnn { Nno , Nne }
@@ -299,6 +308,7 @@
\prg_generate_conditional_variant:Nnn \seq_if_in:Nn { Ne } { F }
\prg_generate_conditional_variant:Nnn \str_if_eq:nn { en , eV } { T , F , TF }
\prg_generate_conditional_variant:Nnn \str_if_eq:nn { Vn } { p }
+\prg_generate_conditional_variant:Nnn \str_if_in:nn { ee } { T }
% ===
@@ -318,9 +328,11 @@
\bool_if:NTF \l__jsonparse_compat_bool {
\prop_new:N \g_jsonparse_entries_prop
\prop_new:N \l__jsonparse_temp_prop
+ \prop_new:N \l__jsonparse_temp_copy_prop
} {
\prop_new_linked:N \g_jsonparse_entries_prop
\prop_new_linked:N \l__jsonparse_temp_prop
+ \prop_new_linked:N \l__jsonparse_temp_copy_prop
}
\tl_new:N \g__jsonparse_json_tl
@@ -906,11 +918,11 @@
\NewDocumentCommand { \JSONParseFilter } { m m m } {
\__jsonparse_warning_undefined_prop:N #2
\group_begin:
- \tl_set_eq:NN \l__jsonparse_temp_tl #2
- \jsonparse_filter:Nn \l__jsonparse_temp_tl {#3}
- \exp_last_unbraced:Nf
+ \prop_set_eq:NN \l__jsonparse_temp_prop #2
+ \jsonparse_filter:Nn \l__jsonparse_temp_prop {#3}
+ \exp_args:NNNV
\group_end:
- \tl_set:NV #1 \l__jsonparse_temp_tl
+ \tl_set:Nn #1 \l__jsonparse_temp_prop
}
% ===
@@ -1210,10 +1222,10 @@
\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}
+ \prop_set_eq:NN \l__jsonparse_temp_copy_prop #1
+ \jsonparse_filter:Nn \l__jsonparse_temp_copy_prop {#2}
\bool_set_true:N \l__jsonparse_prop_map_first_bool
- \jsonparse_parse_keys:NN \l__jsonparse_temp_tl \l__jsonparse_keys_tl
+ \jsonparse_parse_keys:NN \l__jsonparse_temp_prop \l__jsonparse_keys_tl
\tl_use:N \l__jsonparse_keys_tl
\group_end:
}
@@ -1224,13 +1236,13 @@
\tl_new:N #1
}
\group_begin:
- \tl_set_eq:NN \l__jsonparse_temp_tl #2
- \jsonparse_filter:Nn \l__jsonparse_temp_tl {#3}
+ \prop_set_eq:NN \l__jsonparse_temp_copy_prop #2
+ \jsonparse_filter:Nn \l__jsonparse_temp_copy_prop {#3}
\bool_set_true:N \l__jsonparse_prop_map_first_bool
- \jsonparse_parse_keys:NN \l__jsonparse_temp_tl \l__jsonparse_keys_tl
- \exp_last_unbraced:Nf
+ \jsonparse_parse_keys:NN \l__jsonparse_temp_prop \l__jsonparse_keys_tl
+ \exp_args:NNNV
\group_end:
- \exp_args:NNe \jsonparse_parse_to_prop:Nn #1 { \l__jsonparse_keys_tl }
+ \jsonparse_parse_to_prop:Nn #1 \l__jsonparse_keys_tl
}
\cs_new:Npn \__jsonparse_get_array_index:w [ #1 ] #2 \q_stop {
@@ -1262,9 +1274,9 @@
\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}
- \jsonparse_array_count:NN \l__jsonparse_temp_tl \l__jsonparse_array_count_int
+ \prop_set_eq:NN \l__jsonparse_temp_copy_prop #1
+ \jsonparse_filter:Nn \l__jsonparse_temp_copy_prop {#2}
+ \jsonparse_array_count:NN \l__jsonparse_temp_copy_prop \l__jsonparse_array_count_int
\int_use:N \l__jsonparse_array_count_int
\group_end:
}
@@ -1275,12 +1287,12 @@
\tl_new:N #1
}
\group_begin:
- \tl_set_eq:NN \l__jsonparse_temp_tl #2
- \jsonparse_filter:Nn \l__jsonparse_temp_tl {#3}
- \jsonparse_array_count:NN \l__jsonparse_temp_tl \l__jsonparse_array_count_int
- \exp_last_unbraced:Nf
+ \prop_set_eq:NN \l__jsonparse_temp_copy_prop #2
+ \jsonparse_filter:Nn \l__jsonparse_temp_copy_prop {#3}
+ \jsonparse_array_count:NN \l__jsonparse_temp_copy_prop \l__jsonparse_array_count_int
+ \exp_args:NNNV
\group_end:
- \tl_set:NV #1 \l__jsonparse_array_count_int
+ \tl_set:Nn #1 \l__jsonparse_array_count_int
}
\cs_new_protected:Npn \__jsonparse_array_use:n #1 {
@@ -1291,7 +1303,7 @@
}
\bool_if:NTF \l__jsonparse_rescan_bool {
\exp_args:Ne \__jsonparse_rescan:n {
- \prop_item:Ne \l__jsonparse_temp_tl {
+ \prop_item:Ne \l__jsonparse_temp_copy_prop {
\l__jsonparse_array_sep_left_str
\bool_if:NTF \l__jsonparse_zero_based_bool {
\int_eval:n { #1 - 1 }
@@ -1306,7 +1318,7 @@
}
}
} {
- \prop_item:Ne \l__jsonparse_temp_tl {
+ \prop_item:Ne \l__jsonparse_temp_copy_prop {
\l__jsonparse_array_sep_left_str
\bool_if:NTF \l__jsonparse_zero_based_bool {
\int_eval:n { #1 - 1 }
@@ -1327,9 +1339,9 @@
\group_begin:
\keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist
\__jsonparse_warning_unused_keys:
- \tl_set_eq:NN \l__jsonparse_temp_tl #2
- \jsonparse_filter:Nn \l__jsonparse_temp_tl {#3}
- \jsonparse_array_count:NN \l__jsonparse_temp_tl \l__jsonparse_array_count_int
+ \prop_set_eq:NN \l__jsonparse_temp_copy_prop #2
+ \jsonparse_filter:Nn \l__jsonparse_temp_copy_prop {#3}
+ \jsonparse_array_count:NN \l__jsonparse_temp_copy_prop \l__jsonparse_array_count_int
\str_set:Ne \l__jsonparse_array_values_key_str {#4}
\tl_set:Nn \l__jsonparse_array_values_insert_tl {#5}
\bool_set_true:N \l__jsonparse_prop_map_first_bool
@@ -1361,7 +1373,7 @@
\bool_if:NTF \l__jsonparse_rescan_bool {
\tl_gset:cn { JSONParseArrayValue \l__jsonparse_array_keys_index_roman_tl } {
\exp_args:Ne \__jsonparse_rescan:n {
- \prop_item:Ne \l__jsonparse_temp_tl {
+ \prop_item:Ne \l__jsonparse_temp_copy_prop {
\l__jsonparse_array_sep_left_str
\JSONParseArrayIndex
\l__jsonparse_array_sep_right_str
@@ -1372,7 +1384,7 @@
}
} {
\tl_gset:ce { JSONParseArrayValue \l__jsonparse_array_keys_index_roman_tl } {
- \prop_item:Ne \l__jsonparse_temp_tl {
+ \prop_item:Ne \l__jsonparse_temp_copy_prop {
\l__jsonparse_array_sep_left_str
\JSONParseArrayIndex
\l__jsonparse_array_sep_right_str
@@ -1400,7 +1412,7 @@
\bool_if:NTF \l__jsonparse_rescan_bool {
\tl_gset:Nn \JSONParseArrayValue {
\exp_args:Ne \__jsonparse_rescan:n {
- \prop_item:Ne \l__jsonparse_temp_tl {
+ \prop_item:Ne \l__jsonparse_temp_copy_prop {
\l__jsonparse_array_sep_left_str
\JSONParseArrayIndex
\l__jsonparse_array_sep_right_str
@@ -1409,7 +1421,7 @@
}
} {
\tl_gset:Ne \JSONParseArrayValue {
- \prop_item:Ne \l__jsonparse_temp_tl {
+ \prop_item:Ne \l__jsonparse_temp_copy_prop {
\l__jsonparse_array_sep_left_str
\JSONParseArrayIndex
\l__jsonparse_array_sep_right_str
@@ -1448,9 +1460,9 @@
\group_begin:
\keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist
\__jsonparse_warning_unused_keys:
- \tl_set_eq:NN \l__jsonparse_temp_tl #2
- \jsonparse_filter:Nn \l__jsonparse_temp_tl {#3}
- \jsonparse_array_count:NN \l__jsonparse_temp_tl \l__jsonparse_array_count_int
+ \prop_set_eq:NN \l__jsonparse_temp_copy_prop #2
+ \jsonparse_filter:Nn \l__jsonparse_temp_copy_prop {#3}
+ \jsonparse_array_count:NN \l__jsonparse_temp_copy_prop \l__jsonparse_array_count_int
\clist_set:Nn \l__jsonparse_array_map_keys_clist {#4}
\cs_set_eq:NN \__jsonparse_array_map_function_cs: #5
\clist_if_empty:NF \l__jsonparse_array_map_keys_clist {
@@ -1458,10 +1470,10 @@
\clist_map_function:NN \l__jsonparse_array_map_keys_clist
\__jsonparse_array_map_function_generate_cs:n
}
- \l__jsonparse_map_before_tl
+ \l__jsonparse_array_map_code_before_tl
\int_step_function:nN { \l__jsonparse_array_count_int }
\__jsonparse_array_map_function:n
- \l__jsonparse_map_after_tl
+ \l__jsonparse_array_map_code_after_tl
\group_end:
}
@@ -1475,23 +1487,53 @@
}
% ===
-\cs_new:Npn \__jsonparse_array_map_inline:n #1 { }
+\cs_new:Npn \__jsonparse_warning_function_expandable: {
+ \str_if_in:eeT { \tl_to_str:o { \__jsonparse_array_map_inline_code:n { } } }
+ { \c_backslash_str JSONParseValue }
+ { \msg_error:nn { jsonparse } { nested-non-expandable } }
+}
-\NewDocumentCommand { \JSONParseArrayMapInline } { m m +m } {
- \__jsonparse_warning_undefined_prop:N #1
- \cs_gset:Npn \__jsonparse_array_map_inline:n ##1 {#3}
+\cs_new:Npn \__jsonparse_array_map_inline_code:n #1 { }
+
+\cs_new:Npn \__jsonparse_array_map_inline:nn #1#2 {
+ \tl_if_empty:NT \g__jsonparse_array_map_store_in_tl {
+ \__jsonparse_array_map_inline_aux:nn {#1} {#2}
+ }
+}
+
+\cs_new:Npn \__jsonparse_array_map_inline_aux:nn #1#2 {
+ \int_step_function:nnN {
+ \bool_if:nTF {#1} { 0 } { 1 }
+ } {#2} \__jsonparse_array_map_inline_code:n
+}
+\cs_generate_variant:Nn \__jsonparse_array_map_inline_aux:nn { oV }
+
+\NewDocumentCommand { \JSONParseArrayMapInline } { O{} m m +m } {
+ \__jsonparse_warning_undefined_prop:N #2
+ \cs_gset:Npn \__jsonparse_array_map_inline_code:n ##1 {#4}
\group_begin:
- \tl_set_eq:NN \l__jsonparse_temp_tl #1
- \jsonparse_filter:Nn \l__jsonparse_temp_tl {#2}
- \jsonparse_array_count:NN \l__jsonparse_temp_tl \l__jsonparse_array_count_int
+ \keys_set_known:nn { jsonparse / map } {#1} \l__jsonparse_unused_keys_clist
+ \__jsonparse_warning_unused_keys:
+ \prop_set_eq:NN \l__jsonparse_temp_copy_prop #2
+ \jsonparse_filter:Nn \l__jsonparse_temp_copy_prop {#3}
+ \jsonparse_array_count:NN \l__jsonparse_temp_copy_prop \l__jsonparse_array_count_int
\bool_if:NT \l__jsonparse_zero_based_bool {
\int_decr:N \l__jsonparse_array_count_int
}
- \exp_last_unbraced:Nf
+ \tl_if_empty:NF \g__jsonparse_array_map_store_in_tl {
+ \__jsonparse_warning_function_expandable:
+ \exp_last_unbraced:No \tl_if_exist:NF \g__jsonparse_array_map_store_in_tl {
+ \exp_last_unbraced:No \tl_new:N \g__jsonparse_array_map_store_in_tl
+ }
+ \exp_last_unbraced:No \tl_gset:Ne \g__jsonparse_array_map_store_in_tl {
+ \__jsonparse_array_map_inline_aux:oV { \l__jsonparse_zero_based_bool }
+ \l__jsonparse_array_count_int
+ }
+ }
+ \exp_args:NNoV
\group_end:
- \int_step_function:nVN {
- \bool_if:NTF \l__jsonparse_zero_based_bool { 0 } { 1 }
- } \l__jsonparse_array_count_int \__jsonparse_array_map_inline:n
+ \__jsonparse_array_map_inline:nn { \l__jsonparse_zero_based_bool }
+ \l__jsonparse_array_count_int
}
% ===
More information about the tex-live-commits
mailing list.