I’m using: SWI-Prolog version 8.1.17
I’m trying to accept JSON and convert it to Prolog terms in a convenient form.
sample_json('{
"device_location":"st7735",
"hostname":"LCDst7735-d1e72",
"ip_addr":"192.168.0.148",
"version":"Dec 24 2019 13:58:08",
"mac_addr":"4c:11:ae:0d:1e:72",
"arduino_board":"ESP8266_WEMOS_D1MINI",
"mqtt":{
"mqtt_server":"mqtt.geekster.com",
"mqtt_port":1883,
"mqtt_sub_topic":"Smarthome/lcd/4c:11:ae:0d:1e:72",
"mqtt_log_topic":"Smarthome/Log/mqtt"
},
"lcd":{
"display_type":"st7735",
"width":128,
"height":128,
"rotation":0,
"color_depth":"5:6:5",
"fonts":[
{"index":9,"fontname":"FreeSans9pt7b"},
{"index":12,"fontname":"FreeSans12pt7b"},
{"index":18,"fontname":"FreeSans18pt7b"},
{"index":24,"fontname":"FreeSans24pt7b"}
]
}}
').
When I use atom_json_dict(Json,Dict,[]) on the above, the fonts section translates to:
sample_fontslist([
_{fontname:"FreeSans9pt7b",index:9},
_{fontname:"FreeSans12pt7b",index:12},
_{fontname:"FreeSans18pt7b",index:18},
_{fontname:"FreeSans24pt7b",index:24}
]).
And if I do:
sample_fontslist(L), dicts_to_compounds(L, [index, fontname], dict_fill(null),C).
I get:
C = [row(9, "FreeSans9pt7b"), row(12, "FreeSans12pt7b"), row(18, "FreeSans18pt7b"), row(24, "FreeSans24pt7b")].
This is REALLY close to what I want, but instead of “row” as the name I’d like “font”:
[font(9, "FreeSans9pt7b"), font(12, "FreeSans12pt7b"), font(18, "FreeSans18pt7b"), font(24, "FreeSans24pt7b")]
When I look at the source code for dicts_to_compounds there is no option to specify the default_tag as font instead of row.
So I’m wondering what’s the most appropriate way of fixing this. Should I do all of the above and then do a translation from row to font at the end, or was there something I could have done at the atom_json_dict stage to map the anonymous objects to fonts?