Repository navigation
tabularx support #82
|
Older versions (v0.9.10) supported {tabularx} package in \JSONParseArrayValuesMap |
Replies: 2 comments 2 replies
|
Thank you for your enquiry. You did not provide a minimal working example, but the example from the manual indeed does not work with You are right, that current versions of The command \documentclass{article}
\usepackage{jsonparse}
\usepackage{tabularx}
\JSONParse{\myJSONdata}{
{
"array" : [
{
"key_a" : "one" ,
"key_b" : "two"
} ,
{
"key_a" : "three" ,
"key_b" : "four"
}
]
}
}
\begin{document}
\begin{tabularx}{\textwidth}{ c X }
\textbf{key a} &
\textbf{key b} \\ \hline
\JSONParseArrayMapInline{\myJSONdata}{array}{%
\JSONParseValue{\myJSONdata}{array[#1].key_a} &
\JSONParseValue{\myJSONdata}{array[#1].key_b} \\
}
\hline
\end{tabularx}
\end{document}But it really depends on your concrete use case whether this can be a working solution for you or not. I need to investigate why there is this difference between |
|
Hello jasperhabicht! Thank you for clarification. I will try explaining in more detail. In this issue I am using versions \documentclass{article}
\usepackage{jsonparse_0.9.10}
\usepackage{array}
\usepackage{tabularx}
\begin{document}
\JSONParse{\myJSON}
{
{
"array" : [
{
"key_a": "1 val a",
"key_b" : "1 val b"
},
{
"key_a": "2 val a",
"key_b" : "2 val b"
},
{
"key_a": "3 val a",
"key_b" : "3 val b"
}
]
}
}
\newcommand{\myJSONitem}
{
\JSONParseArrayValueI & \JSONParseArrayValueII \\ \hline
}
tabular
\JSONParseArrayValuesMap{\myJSON}{array}[key_a,key_b]{myJSONitem}
[\begin{tabular}{|m{50mm}|m{50mm}|}
\hline
\multicolumn{2}{|c|}{\textbf{array}}\\ \hline
\textbf{key a} & \textbf{key b} \\ \hline]
[\end{tabular}]
\vspace{1em}
tabularx
\JSONParseArrayValuesMap{\myJSON}{array}[key_a,key_b]{myJSONitem}
[\begin{tabularx}{100mm}{|m{50mm}|X|}
\hline
\multicolumn{2}{|c|}{\textbf{array}}\\ \hline
\textbf{key a} & \textbf{key b} \\ \hline]
[\end{tabularx}]
\end{document}When using \JSONParseArrayValuesMap{\myJSON}{array}[key_a,key_b]{myJSONitem}
[\begin{tabularx}{100mm}{|m{50mm}|X|}
\hline
\multicolumn{2}{|c|}{\textbf{array}}\\ \hline
\textbf{key a} & \textbf{key b} \\ \hline]
[\end{tabularx}] will have fatal error and will not build. Yes \ProvidesPackage{jsontable}[json table]
\RequirePackage{jsonparse_1.6.10}
\RequirePackage{array}
\RequirePackage{tabularx}
\NewDocumentCommand{\drawinfotable}{m}
\newcommand{\myJSONitem}
{
\JSONParseArrayValueI & \JSONParseArrayValueII \\ \hline
}
\JSONParseArrayValuesMap{#1}{array}[key_a,key_b]{myJSONitem}
[\begin{tabular}{|m{50mm}|m{50mm}|}
\hline
\multicolumn{2}{|c|}{\textbf{array}}\\ \hline
\textbf{key a} & \textbf{key b} \\ \hline]
[\end{tabular}] but using workaround with \begin{tabularx}{100mm}{|m{90mm}|X|}
\textbf{key a} &
\textbf{key b} \\ \hline
\JSONParseArrayMapInline{#1}{array}{%
\JSONParseValue{#1}{array[#1].key_a} &
\JSONParseValue{#1}{array[#1].key_b} \\
}
\hline
\end{tabularx}table renders and has correct number of rows but all cells display as empty. |
The solution is to use the command
\JSONParseArrayMapInlinebut you need to double the#which is something you always need to do if you want to nest functions to access the relevant argument (the following example assuming the current version ofjsonparse):