TL;DR
How do I print categorized and subcategorized values declared in a JSON file (or in some similar type of file) inside of a LaTeX document?
In my document, I am assigning a bunch of values to variables. For example:
| Variable | Value |
|---|---|
sheep |
Baa |
cow |
Moo |
dog |
Woof |
cat |
Meow |
What I want to do is to reference these variables throughout my document and have them automatically expand to whatever is in the Value column. If I update any of the values and recompile the document, the change will propagate throughout. I know that I could do something like this:
\newcommand{\sheep}{Baa}
But this is undesirable because it will end up polluting my document with a bunch of unorganized macros that I'll have to keep track of. My preamble will end up looking like this:
\newcommand{\sheep}{Baa}
\newcommand{\cow}{Moo}
\newcommand{\dog}{Woof}
\newcommand{\cat}{Meow}
\newcommand{\chicken}{Bawk}
\newcommand{\snake}{Hiss}
\newcommand{\wolf}{Howl}
Now, say I want to put all of these animals into a category called "animals." I would put a dash, for instance, in the macros (i.e., \animals-sheep), but TeX doesn't support that.
What I am wondering is if there is some package or technique that will help me use a JSON file (YML or some other data interchange format is also acceptable) to do something like this:
file: variables.json
{
"animals": {
"sheep": "Baa",
"cow": "Moo",
"canines": {
"dog": "Woof",
"wolf": "Howl",
"legs": 4
},
"cat": "Meow",
"birds": {
"chicken": "bawk",
"robin": "chirp"
}
},
"letters": {
"a": "alpha",
"b": "bravo",
"c": "charlie"
}
}
and then in my LaTeX file:
\documentclass{article}
\title{Animals and Letters}
\autor{Me}
\usepackage{jsonParser}
\jsonInclude{./variables.json}
\begin{document}
\maketitle
Hello there! Here's a demonstration of some animal sounds:
A dog goes \jsonRef{animals.canines.dog} and has \jsonRef{animals.canines.legs} legs. \\
% The line above should output "A dog goes Woof and has 4 legs."
The word \jsonRef{letters.a} starts with the letter ``a"!
% The line above should output "The word alpha starts with the letter “a”!"
\end{document}
If I recompiled the document after updating the value of animals.canines.dog in the ./variables.json to "Bark", then the output should be:
A dog goes Bark and has 4 legs.
The word alpha starts with the letter “a”!
Does anyone have an idea how I can do something like this? Right now, I'm using pdfLaTeX, but anything that supports a normal workflow with biber, gls2bib, and escaping to the shell (for the svg package, for instance) is fine. If LuaTeX is the best option here (which I anticipate may be the case), please provide the appropriate code with explanations and annotations.

_so\benZ_animal_sheep{Baa}. You could parse json in TeX or Lua, but unless you actually need this data elsewhere what does it gain over using a tex syntax file? – David Carlisle Aug 21 '22 at 21:07\animals-sheep. Let's be picky: While in the stage of reading from the .tex-input-file for making tokens TeX doesn't support creating control-sequence-tokens whose name consists of several characters, some of them not being of category 11(letter). But in the stage of expansion you can easily have TeX create such tokens via\csname..\endcsname, e.g.,\csname animals-sheep\endcsname. You might be interested in\CsNameToCsTokenas described in my answer to Why does TeX not allow numbers in command names?. – Ulrich Diez Aug 22 '22 at 02:18