diff options
author | Karl Berry <karl@freefriends.org> | 2025-01-17 20:19:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2025-01-17 20:19:42 +0000 |
commit | d6010e3cb9d5630f4e8de7e2a1835da8a17637b9 (patch) | |
tree | 2e279d786a4ad2d4fb642a1d92fc0794b26fe2d2 /Master | |
parent | 79d932f52d98fa0bd2b9f40174645c8b98f41f0f (diff) |
jsonparse (17jan25)
git-svn-id: svn://tug.org/texlive/trunk@73488 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/latex/jsonparse/README.md | 2 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf | bin | 523304 -> 530506 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex | 50 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty | 69 |
4 files changed, 101 insertions, 20 deletions
diff --git a/Master/texmf-dist/doc/latex/jsonparse/README.md b/Master/texmf-dist/doc/latex/jsonparse/README.md index b440c4ef696..b2b1989b078 100644 --- a/Master/texmf-dist/doc/latex/jsonparse/README.md +++ b/Master/texmf-dist/doc/latex/jsonparse/README.md @@ -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) diff --git a/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf b/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf Binary files differindex 2dfc684114d..91005708342 100644 --- a/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf +++ b/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf diff --git a/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex b/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex index b6612bb0607..25bff6e365b 100644 --- a/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex +++ b/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex @@ -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,9 +315,26 @@ The first optional argument can be used to pass options to the command that are 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>} @@ -472,6 +490,30 @@ Using the above example, the mechanism could be implemented as follows: \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. diff --git a/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty b/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty index 92d5610b25d..4f00eb5a929 100644 --- a/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty +++ b/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty @@ -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,26 +1082,61 @@ \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 + } + \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 } - \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: + \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 { @@ -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 } % === |