texlive[76161] Master/texmf-dist: jsonparse (27aug25)
commits+karl at tug.org
commits+karl at tug.org
Wed Aug 27 22:12:21 CEST 2025
Revision: 76161
https://tug.org/svn/texlive?view=revision&revision=76161
Author: karl
Date: 2025-08-27 22:12:20 +0200 (Wed, 27 Aug 2025)
Log Message:
-----------
jsonparse (27aug25)
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-08-27 20:12:10 UTC (rev 76160)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/README.md 2025-08-27 20:12:20 UTC (rev 76161)
@@ -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-08-27 20:12:10 UTC (rev 76160)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex 2025-08-27 20:12:20 UTC (rev 76161)
@@ -11,8 +11,8 @@
% This work has the LPPL maintenance status `maintained'.
%
\documentclass[a4paper]{article}
-\def\jsonparsefileversion{1.6.5}
-\def\jsonparsefiledate{11 August 2025}
+\def\jsonparsefileversion{1.6.6}
+\def\jsonparsefiledate{27 August 2025}
\usepackage[T1]{fontenc}
\usepackage{Alegreya}
@@ -308,6 +308,7 @@
\changes{v1.6.0}{2025/05/10}{Renaming of L3 functions. Bug fixes.}
%\changes{v1.6.1}{2025/06/03}{Bug fixes. FAQ in documentation.}
%\changes{v1.6.5}{2025/08/11}{Bug fixes.}
+\changes{v1.6.6}{2025/08/27}{Various improvements. Added sockets for preparsing.}
\begin{document}
\vspace*{-1cm}
@@ -900,11 +901,73 @@
\end{macrodef}
The key \macro{global} can be used together with the key \macro{store in} to globally set the value of the relevant token list. Detailed information about the key \macro{store in} can be \hyperlink{key:storein}{above}.
+\section{Preparsing via sockets}
+
+The package provides two sockets \macro{jsonparse/preparse} and \macro{jsonparse/preparse-file} using which the code for the procedure for rescanning the JSON input can be changed. The code provided by the sockets should populate the token list \macro{\g_jsonparse_json_tl} with data that is eventually parsed into the property list for further use.
+
+Two default plugs are provided and assigned per default for the two sockets. Both sockets require exactly one argument which can be referred to by \macro{#1} in the definition of the plugs. For the socket \macro{jsonparse/preparse} which is used in the command \macro{\JSONParse}, this represents the provided JSON input. For the socket \macro{jsonparse/preparse-file} which is used in the command \macro{\JSONParseFromFile}, this represents the file name. The two default plugs are defined as follows:
+
+\begin{codeexample}
+\socket_new_plug:nnn { jsonparse / preparse } { default } {
+ \tl_set:Nn \obeyedline { ~ }
+ \tl_gset_rescan:Nne \g_jsonparse_json_tl {
+ \cctab_select:N \c_jsonparse_json_cctab
+ } {#1}
+}
+\end{codeexample}
+
+\begin{codeexample}
+\socket_new_plug:nnn { jsonparse / preparse-file } { default } {
+ \file_get:nnN {#1} { \cctab_select:N \c_jsonparse_json_cctab }
+ \g_jsonparse_json_tl
+}
+\end{codeexample}
+
+It is, for example, possible to make use of this mechanism by defining a new socket to parse JSONL files which consist of a number of JSON objects separated by a line break:
+
+\begin{codeexample}
+\socket_new_plug:nnn { jsonparse / preparse } { jsonl } {
+ \tl_set:Nn \obeyedline { , }
+ \tl_gset_rescan:Nne \g_jsonparse_json_tl {
+ \cctab_select:N \c_jsonparse_json_escape_cctab
+ } { [ #1 ] }
+}
+\socket_assign_plug:nn { jsonparse / preparse } { jsonl }
+\end{codeexample}
+
+\warning Changing the rescanning procedure via the provided sockets requires indepth knowledge about how the parsing procedure works. It also requires knowledge about how TeX deals with category codes and control sequences.
+
\section{L3 commands}
The following token variables and commands are provided for defining user functions by package authors. For the conditional functions described below, apart from the variant that provides a true and a false branch, the and variants that only provide an argument for the true or for the false branch respectively are defined as well which is indicated by the letters {\itshape\macro{TF}} printed in italics. Commands marked with a star (\expandablestar) are fully expandable.
\begin{macrodef}
+|\c_jsonparse_json_cctab|
+\end{macrodef}
+The token variable \macro{\c_jsonparse_json_cctab} holds the category code table that is used for rescanning JSON input. The defintion is as follows:
+
+\begin{codeexample}
+\cctab_const:Nn \c_jsonparse_json_cctab {
+ \cctab_select:N \c_str_cctab
+ \char_set_catcode_space:n { 9 }
+ \char_set_catcode_escape:n { 92 }
+ \bool_lazy_or:nnF {
+ \sys_if_engine_xetex_p:
+ } {
+ \sys_if_engine_luatex_p:
+ } {
+ \int_step_function:nnN { 128 } { 255 }
+ \char_set_catcode_active:n
+ }
+}
+\end{codeexample}
+
+\begin{macrodef}
+|\g_jsonparse_json_tl|
+\end{macrodef}
+The token variable \macro{\g_jsonparse_json_tl} holds the rescanned JSON input before it is parsed by the command \macro{\jsonparse_parse:n}.
+
+\begin{macrodef}
|\g_jsonparse_entries_prop|
\end{macrodef}
The token variable \macro{\g_jsonparse_entries_prop} holds as property list all elements of a JSON data structure that was parsed by the command \macro{\jsonparse_parse:n}.
Modified: trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty 2025-08-27 20:12:10 UTC (rev 76160)
+++ trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty 2025-08-27 20:12:20 UTC (rev 76161)
@@ -10,7 +10,7 @@
%
% This work has the LPPL maintenance status `maintained'.
%
-\ProvidesExplPackage {jsonparse} {2025-08-11} {1.6.5}
+\ProvidesExplPackage {jsonparse} {2025-08-27} {1.6.6}
{A handy way to parse, store and access JSON data from files or strings in LaTeX documents}
\msg_new:nnn { jsonparse } { old-kernel } {
@@ -39,31 +39,26 @@
}
\msg_new:nnn { jsonparse } { parsing-error-generic } {
- \msg_error_text:n { jsonparse } \iow_newline:
Could ~ not ~ parse ~ JSON. \iow_newline:
Parsing ~ error ~ at ~ key ~ `#1` ~ with ~ value ~ `#2`.
}
\msg_new:nnn { jsonparse } { parsing-error-comma } {
- \msg_error_text:n { jsonparse } \iow_newline:
Could ~ not ~ parse ~ JSON. \iow_newline:
Misplaced ~ comma.
}
\msg_new:nnn { jsonparse } { parsing-error-colon } {
- \msg_error_text:n { jsonparse } \iow_newline:
Could ~ not ~ parse ~ JSON. \iow_newline:
Misplaced ~ colon ~ at ~ key ~ #1.
}
\msg_new:nnn { jsonparse } { parsing-error-key } {
- \msg_error_text:n { jsonparse } \iow_newline:
Could ~ not ~ parse ~ JSON. \iow_newline:
Missing ~ key ~ in ~ object.
}
\msg_new:nnn { jsonparse } { nested-non-expandable } {
- \msg_error_text:n { jsonparse } \iow_newline:
Non-expandable ~ commands ~ such ~ as ~ \token_to_str:N \JSONParseValue \c_space_tl
not ~ allowed ~ in ~ stored ~ inline ~ function. \iow_newline:
Use ~ \token_to_str:N \JSONParseExpandableValue \c_space_tl instead.
@@ -70,37 +65,30 @@
}
\msg_new:nnn { jsonparse } { file-not-found } {
- \msg_error_text:n { jsonparse } \iow_newline:
Could ~ not ~ find ~ file ~ #1.
}
\msg_new:nnn { jsonparse } { file-exists } {
- \msg_error_text:n { jsonparse } \iow_newline:
File ~ #1 ~ already ~ existing.
}
\msg_new:nnn { jsonparse } { escape-char-unknown } {
- \msg_error_text:n { jsonparse } \iow_newline:
Escape ~ character ~ #1 ~ unknown.
}
\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 } { not-array-item } {
- \msg_error_text:n { jsonparse } \iow_newline:
Key ~ does ~ not ~ represent ~ an ~ array ~ item: ~ #1
}
\msg_new:nnn { jsonparse } { key-unknown } {
- \msg_warning_text:n { jsonparse } \iow_newline:
Ignoring ~ key: ~ #1. \iow_newline:
The ~ key ~ is ~ either ~ unknown ~ or ~
not ~ supported ~ by ~ this ~ function.
@@ -107,12 +95,10 @@
}
\msg_new:nnn { jsonparse } { saving-external } {
- \msg_info_text:n { jsonparse } \iow_newline:
Saving ~ to ~ external ~ file: ~ #1.
}
\msg_new:nnn { jsonparse } { loading-external } {
- \msg_info_text:n { jsonparse } \iow_newline:
Loading ~ from ~ external ~ file: ~ #1.
}
@@ -371,7 +357,7 @@
\scan_new:N \s__jsonparse_stop
\scan_new:N \s__jsonparse_split
-\tl_new:N \g__jsonparse_json_tl
+\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_temp_copy_tl
@@ -409,7 +395,6 @@
\tl_new:N \l__jsonparse_array_use_temp_tl
\clist_new:N \l__jsonparse_array_map_keys_clist
-\str_new:N \l__jsonparse_array_map_function_str
\int_new:N \g__jsonparse_array_map_inline_int
\tl_new:N \l__jsonparse_externalize_file_data_tl
@@ -418,7 +403,7 @@
% ===
-\cctab_const:Nn \c__jsonparse_json_escape_cctab {
+\cctab_const:Nn \c_jsonparse_json_cctab {
\cctab_select:N \c_str_cctab
\char_set_catcode_space:n { 9 }
\char_set_catcode_escape:n { 92 }
@@ -1181,6 +1166,28 @@
% ===
+\socket_new:nn { jsonparse / preparse } { 1 }
+
+\socket_new_plug:nnn { jsonparse / preparse } { default } {
+ \tl_set:Nn \obeyedline { ~ }
+ \tl_gset_rescan:Nne \g_jsonparse_json_tl {
+ \cctab_select:N \c_jsonparse_json_cctab
+ } {#1}
+}
+
+\socket_assign_plug:nn { jsonparse / preparse } { default }
+
+\socket_new:nn { jsonparse / preparse-file } { 1 }
+
+\socket_new_plug:nnn { jsonparse / preparse-file } { default } {
+ \file_get:nnN {#1} { \cctab_select:N \c_jsonparse_json_cctab }
+ \g_jsonparse_json_tl
+}
+
+\socket_assign_plug:nn { jsonparse / preparse-file } { default }
+
+% ==
+
\cs_new_protected:Npn \__jsonparse_nested_construct_cs:Nnn #1#2#3 {
\cs_set:Npn #1 #2 ##1 #3 #2 ##2 #3 {
\prop_item:ce {##1} {##2}
@@ -1188,7 +1195,7 @@
}
\cs_generate_variant:Nn \__jsonparse_nested_construct_cs:Nnn { Noo }
-\cs_new_protected:Npn \__jsonparse_protect_escape_sequeces: {
+\cs_new_protected:Npn \__jsonparse_protect_escape_sequences: {
\clist_map_inline:nn { " , / , \c_backslash_str , b , f , n , r , t , u } {
\cs_set:cpn {##1} { \exp_not:c {##1} }
}
@@ -1218,16 +1225,15 @@
} {
\prop_new_linked:N #2
}
- \tl_gclear:N \g__jsonparse_json_tl
+ \tl_gclear:N \g_jsonparse_json_tl
\group_begin:
- \__jsonparse_protect_escape_sequeces:
+ \__jsonparse_protect_escape_sequences:
\__jsonparse_nested_construct_cs:Noo \$ { \c_left_brace_str } { \c_right_brace_str }
% backward compatibility
\__jsonparse_nested_construct_cs:Noo \x { \c_left_brace_str } { \c_right_brace_str }
% ===
- \tl_set:Nn \obeyedline { ~ }
- \tl_gset_rescan:Nne \g__jsonparse_json_tl { \cctab_select:N \c__jsonparse_json_escape_cctab } {#3}
- \jsonparse_gset_parse:Ne #2 { \g__jsonparse_json_tl }
+ \socket_use:nn { jsonparse / preparse } {#3}
+ \jsonparse_gset_parse:Ne #2 { \g_jsonparse_json_tl }
\group_end:
\bool_if:NT \l__jsonparse_externalize_bool {
\__jsonparse_externalize:Nn #2 { \l__jsonparse_externalize_file_name_tl .jsonparse }
@@ -1264,12 +1270,11 @@
} {
\prop_new_linked:N #2
}
- \tl_gclear:N \g__jsonparse_json_tl
+ \tl_gclear:N \g_jsonparse_json_tl
\group_begin:
- \__jsonparse_protect_escape_sequeces:
- \file_get:nnN {#3} { \cctab_select:N \c__jsonparse_json_escape_cctab } \l__jsonparse_externalize_file_data_tl
- \tl_gset_eq:NN \g__jsonparse_json_tl \l__jsonparse_externalize_file_data_tl
- \jsonparse_gset_parse:Ne #2 { \g__jsonparse_json_tl }
+ \__jsonparse_protect_escape_sequences:
+ \socket_use:nn { jsonparse / preparse-file } {#3}
+ \jsonparse_gset_parse:Ne #2 { \g_jsonparse_json_tl }
\group_end:
\bool_if:NT \l__jsonparse_externalize_bool {
\__jsonparse_externalize:Nn #2 { \l__jsonparse_externalize_file_name_tl .jsonparse }
@@ -1430,9 +1435,9 @@
#3
} {
\bool_if:nTF {#2} {
- \tl_gset:Nn #1 {#3}
+ \tl_gset:Nn #1 {#3}
} {
- \tl_set:Nn #1 {#3}
+ \tl_set:Nn #1 {#3}
}
}
}
More information about the tex-live-commits
mailing list.