On Fri, 13 Feb 2026, Andreas Hof via ntg-context wrote:

> Hi all here,
> 
> I have a question in the area of the json module and in general about the 
> interaction between Lua and ConTeXt.
> 
> In m-json.mkxl we have for example:
> 
>     interfaces.implement {
>         name      = "tablefield",
>         actions   = function(namespace,name)
>             local data = field(namespace,name)
>             if data then
>                 context(data)
>             end
>         end,
>         arguments = "2 arguments",
>         public    = true,
>         protected = true,
>     }
>  
> Means, that, if I ask for a table field from json file the value will be 
> typeset through context(data).
> 
> Is there any possibility to check the value passed from Lua to ConTeXt on 
> ConTeXt level? 
> 
> I like to use the json module for getting addresses for a mass lettering. 
> Prominent examples, where a check of the value from a json-database is needed 
> is the title of a person (typeset it plus a space or do nothing if empty), 
> or if you need to have alternatives for an opening sentence depending on the 
> salutation or gender. Or whatever you can think of in a mass letter depending 
> on the dataset ...

For such tasks, one option is convert the data to a lua table, and then typeset 
using CLD. For example, 

  addresses = utilities.json.load("addr.json")
  inspect(addresses)

gives

table={
 ["records"]={
  {
   ["firstname"]="Hildegard",
   ["location"]="Bingen am Rhein",
   ["name"]="von Bingen",
   ["salutation"]="Mrs.",
   ["street"]="past road 1",
   ["title"]="",
   ["zip"]="00000",
  },
  {
   ["firstname"]="Hippokrates",
   ["location"]="Kos",
   ["name"]="von Kos",
   ["salutation"]="Mr.",
   ["street"]="long ago road 1",
   ["title"]="Dr.",
   ["zip"]="00001",
  },
 },
}

So, you can loop over the entries, check for title/salutation and write the 
logic in lua (no need to worry about expansion and stuff). 

Aditya

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to