Schema change to JSON?

I have an extension with schema key type ‘aa{ss}’, basically a list of maps with string keys and values. Now I need a new string key whose value is itself an array of maps with string keys and values.

I’ve been playing with replacing the schema with ‘s’ with JSON as the value, something like:

'[{"name": "Footeware", "url": "https://footeware.ca", "frequency": 120, "timeout": 10, "verb": "HEAD", "notifies": false, "visible": true, "ignoreTLSErrors": false, "ignoreRedirects": false, "headers": ['Authorization': 'Basic abc123']}]'

Where headers is an array of name-value pairs for HTTP request headers. I’ve got it working but I’m wondering if it’s the right decision. It means using proper booleans and ints rather than strings for some of the properties, the new headers array works fine, and the migration is relatively simple. I’m not seeing a downside and that worries me. I feel like I’m not seeing the whole picture maybe.

Any opinions please?

Let me put it another way. Is there any way I can use variants to store like this?

array of maps where the keys are all strings but the values can be string, int, boolean, or another map of string to string

Or all of these?

aa{ss}
aa{si}
aa{sb}
aa{sa{ss}}

I think what you want is aa{sv}. The v let you store another variant inside the dictionary. The GJS docs have an example that showcases how to deal with more complex cases such as these.

Thanks, I don’t know how I missed that. If they can do type="(sasa{sa{sv}})", I should be able to figure this out. Still not sure of the advantages of this over json though :frowning:

I got it working, sorta. These three keys compile.

The first is the old schema I’m migrating from, “aa{ss}”. Note booleans and ints are strings. There’s a new requirement to use http request headers.

The second adds the required ‘headers’ dict key with an array value. Note the whole default value is wrapped in single-quotes as a JSON string and its type is “s”.

The third also adds headers and is using gvariant type “aa{sv}”. Note that all values are required to be in angle brackets which require entity-encoding. Also the array cannot be empty.

I understand GVariants are used for DBus and some other purposes but, in this case, it seems to me that going with json is easier to maintain and debug.

Which would you choose?

<key type="aa{ss}" name="settings-original">
	<default>[
        {
            "name": "Footeware",
            "url": "https://footeware.ca",
            "frequency": "120",
            "timeout": "10",
            "isGet": "false",
            "notifies": "false",
            "visible": "true",
            "ignoreTLSErrors": "false",
            "ignoreRedirects": "false"
        }
    ]</default>
</key>
<key type="s" name="settings-json">
    <default>'[
        {
            "name": "Footeware",
            "url": "https://footeware.ca",
            "frequency": 120,
            "timeout": 10,
            "verb": "HEAD",
            "notifies": false,
            "visible": true,
            "ignoreTLSErrors": false,
            "ignoreRedirects": false,
            "headers": [];
        }
    ]'</default>
</key>
<key type="aa{sv}" name="settings-gvariant">
    <default>[
        {
            "name": &lt;"Footeware"&gt;,
            "url": &lt;"https://footeware.ca"&gt;,
            "frequency": &lt;120&gt;,
            "timeout": &lt;10&gt;,
            "verb": &lt;"HEAD"&gt;,
            "notifies": &lt;false&gt;,
            "visible": &lt;true&gt;,
            "ignoreTLSErrors": &lt;false&gt;,
            "ignoreRedirects": &lt;false&gt;,
            "headers": &lt;[{"From": "example@example.com"}]&gt;
        }
    ]</default>
</key>