Parsing Morpheus Instance information - interfaces

I have a situation where I am looping through Morpheus interfaces, and trying to see if it has an optional domain on it (the domains are defined on the network segment in NSX-T and get populated in Morpheus).

As I loop through the interfaces, the domain is referenced using the tag:

<%= instance.container.server.interfaces[i].domain %>

What gets printed out with this macro, is something that is very messy to parse:

[name:nfv.foo.net, fqdn:nfv.foo.net., ouPath:null]

Kind of a half-javascript, half-json array, I guess? And, if you look at fqdn, there is an extra dot at the end of it which adds some more fun if you decide to extract fqdn instead of name.

Currently, I have some some super complex bash, sed, et al to parse this. Someone suggested I try to use jq and parse it json-style, and I tried that today and noticed that it blew up constantly trying to parse this. Is there an elegant succinct way to parse this? Because you would not believe the length and complexity of the bash script currently in place to do this. I would like to simplify it if I can, so that people can understand the logic better.

how about <%= instance.container.server.interfaces[i].domain?.name %> to just return the name?
or <%= instance.container.server.interfaces[i].domain?.name ?: nodomain %> to return nodomain if no domain.

can also do <%= instance.container.server.interfaces[i].domain.encodeAsJSON() %>

is this Jinja2 syntax? Javascript? i probably need to read up on the tricks and syntax.
what does the “domain?.name” mean? if the domain is present print the name?
and, can you explain what the “domain?.name ?: nodomain” means?

i can try out that encodeAsJSON() and see what result i get from that - let me check that out.

okay did some testing. the encodeAsJSON() puts the array in curlies, but unfortunately because the name value pairs attributes are not quoted (and have dots in them to boot), jq cannot parse them.

[foo@ans01 bash]# echo "{name:nfv.foo.net,fqdn:nfv.foo.net.,ouPath:null}" | jq
parse error: Invalid literal at line 1, column 6

[foo@ans01 bash]# echo '{"name":"nfv.foo.net","fqdn":"nfv.foo.net","ouPath":"null"}' | jq
{
  "name": "nfv.foo.net",
  "fqdn": "nfv.foo.net",
  "ouPath": "null"
}

so the encodeAsJSON() certainly helps get you there, but unless there is an easy way to get the name value pairs quoted, some work still to do.