Array Iterator #87
|
Hello! \JSONParse{\myJSON}
{
{
"array" : [
{
"key_a": "one",
"key_b" : "two"
},
{
"key_a": "three",
"key_b" : "four"
}
]
}
}I want to use "pointer to array item" as value. \JSONParse{\myJSONid}
{
{
"array" : [
{
"id": 1,
"key_a": "one",
"key_b" : "two"
},
{
"id": 2,
"key_a": "three",
"key_b" : "four"
}
]
}
}We can use it as \begin{itemize}
\JSONParseArrayMapInline{\myJSONid}{array}{
\item Group \JSONParseValue{\myJSONid}{array[#1].id}:
\begin{itemize}
\item key a: \JSONParseValue{\myJSONid}{array[#1].key_a};
\item key b: \JSONParseValue{\myJSONid}{array[#1].key_b};
\end{itemize}
}
\end{itemize}This approach demands to use additional key in JSON, but we actually do not need this key, we already have pointer to array item. ...
\item Group __iterator{array[#1]}__:
... |
Answered by
jasperhabicht
Mar 10, 2026
Replies: 1 comment 2 replies
|
If you use \documentclass{article}
\usepackage{jsonparse}
\JSONParse[zero-based=false]{\myJSON}{
{
"array" : [
{
"key_a": "one",
"key_b" : "two"
},
{
"key_a": "three",
"key_b" : "four"
}
]
}
}
\begin{document}
\begin{itemize}
\JSONParseArrayMapInline[zero-based=false]{\myJSON}{array}{
\item Group #1:
\begin{itemize}
\item key a: \JSONParseValue{\myJSON}{array[#1].key_a};
\item key b: \JSONParseValue{\myJSON}{array[#1].key_b};
\end{itemize}
}
\end{itemize}
\end{document} |
2 replies
Answer selected by
Zumiha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use
\JSONParseArrayMapInlinelike in your example, the index can simply be accessed with#1. Of course, this would return0for the first item, because indices start with zero per default, but you could change this usingzero-based=false: