Re: Re: How to join multiple parts of one data container

"'Bas van der Vlies' via help-cfengine" <[email protected]> Thu, 27 Jul 2023 11:19:05 +0200
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>

On 27/07/2023 10:10, Michal Švamberg wrote:
> Hi,
> the simplified source code is in the email attachment. When I run it:
> # cf-agent -Kf ./test.cf -C --show-evaluated-vars=default:main\\.level
>     error: Error parsing JSON expression '[hwraid] ]': Unable to parse 
> json data as array, did not start with '['
>     error: Error parsing JSON expression '[hwraid] ]': Unable to parse 
> json data as array, did not start with '['
>     error: Error parsing JSON expression '[icinga], 
> repos[ubuntu_16][hwraid] ]': Unable to parse json data as array, did not 
> start with '['
>     error: Error parsing JSON expression '[icinga], 
> repos[ubuntu_16][hwraid] ]': Unable to parse json data as array, did not 
> start with '['
> ...
> Variable name                            Variable value                 
>                                Meta tags                               
>   Comment
> default:main.level1_serialized           
> [{"debian":{"Suites":["bookworm","bookworm-backports","bookworm-proposed-updates","bookworm-updates"],"URIs":"http://deb.debian.org/debian"},"debian-security":{"Suites":["bookworm-security"],"URIs":"http://deb.debian.org/debian-security"},"icinga":{"Suites":["icinga-bookworm"],"URIs":"https://packages.icinga.com/debian"}},{"hwraid":{"Suites":["stretch"],"Types":["deb"],"URIs":"https://hwraid.le-vert.net/debian"},"ubuntu":{"Suites":["xenial","xenial-backports","xenial-proposed","xenial-updates","xenial-security"],"URIs":"http://cz.archive.ubuntu.com/ubuntu"},"ubuntu-security":{"Suites":["xenial-security"],"URIs":"http://cz.archive.ubuntu.com/ubuntu"}}] source=promise
> default:main.level1_single               
> [{"hwraid":{"Suites":["stretch"],"Types":["deb"],"URIs":"https://hwraid.le-vert.net/debian"},"ubuntu":{"Suites":["xenial","xenial-backports","xenial-proposed","xenial-updates","xenial-security"],"URIs":"http://cz.archive.ubuntu.com/ubuntu"},"ubuntu-security":{"Suites":["xenial-security"],"URIs":"http://cz.archive.ubuntu.com/ubuntu"}}] source=promise
> 
> I get level1* variables only. Is there any way to do this for the second 
> level as well?
> 

Michal,

  The problem is that in JSON you can have a list of dictionaries/hashes 
but not a list of items, eg:
```
[ 
 

     Types: [ deb ], 
 

     URIs: https://hwraid.le-vert.net/debian 
 

]
```

jq '.' list.json
```
11:16 r10n17.lisa.surfsara.nl:~
root# jq '.' list.json
parse error: ':' not as part of an object at line 2, column 12
```


-- 
--
Bas van der Vlies
| High Performance Computing & Visualization | SURF| Science Park 140 | 
1098 XG  Amsterdam
| T +31 (0) 20 800 1300  | [email protected] | www.surf.nl |

-- 
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/94904cb7-83a6-ddb3-f8fe-2eadd8aa392d%40surf.nl.