Repository navigation
Could there be an expandable ArrayMap? #86
|
In the following, \documentclass{article}
\usepackage{jsonparse}
\JSONParse{\myJSONdata}{{"array":["a-b"]}}
\typeout{Line 4: \JSONParseValue{\myJSONdata}{array[0]}}
\typeout{Line 5: \JSONParseExpandableValue{\myJSONdata}{array[0]}}
\ExplSyntaxOn
\newcommand{\splitValues}{
\item original: ~ \JSONParseArrayValue
\seq_set_split:Nne \l_tmpa_seq { - } { \JSONParseArrayValue }
\item using~seq~items: ~ \seq_item:Nn \l_tmpa_seq {1} ~ and ~ \seq_item:Nn \l_tmpa_seq {2}
\exp_args:NNe \str_set:Nn \l_tmpa_str { \seq_item:Nn \l_tmpa_seq {1} }
\exp_args:NNe \str_set:Nn \l_tmpb_str { \seq_item:Nn \l_tmpa_seq {2} }
\item using~tmp~variables: ~ \l_tmpa_str{} ~ and ~ \l_tmpb_str
}
\ExplSyntaxOff
\begin{document}
\begin{itemize}
\JSONParseArrayMapFunction{\myJSONdata}{array}{\splitValues}
\JSONParseArrayMapFunction[rescan=false]{\myJSONdata}{array}{\splitValues}
\end{itemize}
\end{document}we see that It seems that the
|
Replies: 2 comments
|
Thank you for your inquiry! Expandability in the context of handling arrays has been an issue from the very start and I tried to improve the existing functions already. I need to think about this again, check the code and eventually may need to revisit this again which can take some time. For now, this is not yet an answer, but only some first thoughts (which may or may not be of much help to your concrete case but could help in trying other approaches): The function In some cases you can also try to use the |
|
Now that I read your issue again in more detail, it rather seems to be an problem with rescanning. Due to the fact that I discovered that the package code can be improved in this regard. As from version 1.7.0 your code snippet should work as expected. In general, you can make use of \documentclass{article}
\usepackage{jsonparse}
\JSONParse{\myJSONdata}{{"array":["\\textbf{a}-b"]}}
\ExplSyntaxOn
\newcommand{\splitValues}{
\item original: ~ \jsonparse_rescan:n { \JSONParseArrayValue }
\jsonparse_set_rescan:Nn \l_tmpa_tl { \JSONParseArrayValue }
\seq_set_split:NnV \l_tmpa_seq { - } \l_tmpa_tl
\item using~seq~items: ~ \seq_item:Nn \l_tmpa_seq {1} ~ and ~ \seq_item:Nn \l_tmpa_seq {2}
}
\ExplSyntaxOff
\begin{document}
\begin{itemize}
\JSONParseArrayMapFunction[rescan=false]{\myJSONdata}{array}{\splitValues}
\end{itemize}
\end{document} |

Now that I read your issue again in more detail, it rather seems to be an problem with rescanning. Due to the fact that
\tl_rescan:nnis not expandable, there is no straight-forward way to process an expandable and also rescanned token list. The typical way to overcome this problem is to store the rescanned result in another token list variable and then use this.I discovered that the package code can be improved in this regard. As from version 1.7.0 your code snippet should work as expected.
In general, you can make use of
\jsonparse_rescan:nand/or\jsonparse_set_rescan:Nnto have better control about when and where the rescanning takes place: