5 ms·
you could always do an S-expression-esque DSL in JSON ;) ['book', {'id': '...'}, ['title', {}, ...], ['chapter', {'id': 0}, ['title', {}, 'Chap
by uryga 7y ago
you could always do an S-expression-esque DSL in JSON ;)
['book', {'id': '...'},
['title', {}, ...],
['chapter', {'id': 0},
['title', {}, 'Chapter 1'],
...
],
['chapter', {'id': 1},
...
],
]
more realistically, you could just represent it with the AST of that XML, i.e
{
'type': 'book',
'attrs': {'id': ...},
'children': [
{
'type': 'title',
'children': ['Simple book']
},
{
'type': 'chapter',
...
},
{
'type': 'chapter',
...
},
...
]
}
so you could do that emphasis bit as
[
'this text nees more',
{'type': 'emphasis',
'children': ['emotion']},
'!'
]
hellish to write by hand but probably okay for a program to consume (modulo all the XML libs/tooling you can't use). and you could probably even write some kind of schema for it.
if i actually had to represent that data, i'd also move some child nodes into attributes, e.g. make all nodes with 'type': 'book' also have a 'title' attribute, like you would if you had an AST datatype