3 ms·
Something like this (very simplified): let $array := [{"foo":0,"bar":"tztz"},{"foo":"hello","bar":null},{"foo":true,"bar":"yes"}] let $value := for $object
by lichtenberger 5y ago
Something like this (very simplified):
let $array := [{"foo":0,"bar":"tztz"},{"foo":"hello","bar":null},{"foo":true,"bar":"yes"}]
let $value := for $object in $array
return
let $fields := bit:fields($object)
let $len := bit:len($fields)
for $field at $pos in $fields
return if ($pos < $len) then (
$object=>$field || ","
) else (
$object=>$field || "\n"
)
return string-join($value,"")
will output:
0,tztz
hello,null
true,yes
- lichtenberger 5y agoOf course you can simply create a module with something like the above snippet as a function for reuse. Or I can add a built-in function for flattening like this or as in pandas.
- kbrazil 5y agoYou could do something like this in pure python without the json loading boilerplate with jello[0]. An interactive TUI for jello called jellex[1} is also available. (I am the author) [0] https://github.com/kellyjonbrazil/jello https://github.com/kellyjonbrazil/jello [1] https://github.com/kellyjonbrazil/jellex https://github.com/kellyjonbrazil/jellex
- lichtenberger 5y agoJSON loading boilerplate? Is it also a compiler with sophisticated optimizations during compile time? :)