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

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

  It is indeed strange i got it working but I think you had the same 
solution:
  * "level2_single" data => mergedata('[]', "repos[ubuntu_16][hwraid]");

and the second one does not make sense for me `level1_serialized` 
because the keys for me get override because they are the same

What is the main difference that level 1 returns:
  * keywords with hashes --> debian --> { values } => I assume a 
getlist function()

level2 is only returning
  * keyword:value => want is not a list somehow

On 27/07/2023 12:54, Michal Švamberg wrote:
> I'm sorry, I forgot the attachment.
> Michal
> 
> čt 27. 7. 2023 v 12:52 odesílatel Michal Švamberg <[email protected] 
> <mailto:[email protected]>> napsal:
> 
>     Hi Bas,
>     I fixed mistakes in JSON (remove commas at end of lists), now is it
>     valid.
>     I tried some changes in JSON structure (change hash to list, ...)
>     without solving the problem.
>     The base question is why work:
>     "level1_single" data => '[ repos[ubuntu_16] ]';
>     but not working
>     "level1_single" data => '[ repos[ubuntu_16][hwraid] ]';
>     Both keys ("ubuntu_16" and "hwraid") are hashes, not lists. The
>     inside structure is irrelevant (or not?).
> 
>     Thanks
>     Michal Svamberg
> 
> 
> 
>     čt 27. 7. 2023 v 11:19 odesílatel Bas van der Vlies
>     <[email protected] <mailto:[email protected]>> napsal:
> 
> 
> 
>         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 <http://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 <http://deb.debian.org/debian>"},"debian-security":{"Suites":["bookworm-security"],"URIs":"http://deb.debian.org/debian-security <http://deb.debian.org/debian-security>"},"icinga":{"Suites":["icinga-bookworm"],"URIs":"https://packages.icinga.com/debian <https://packages.icinga.com/debian>"}},{"hwraid":{"Suites":["stretch"],"Types":["deb"],"URIs":"https://hwraid.le-vert.net/debian <https://hwraid.le-vert.net/debian>"},"ubuntu":{"Suites":["xenial","xenial-backports","xenial-proposed","xenial-updates","xenial-security"],"URIs":"http://cz.archive.ubuntu.com/ubuntu <http://cz.archive.ubuntu.com/ubuntu>"},"ubuntu-security":{"Suites":["xenial-security"],"URIs":"http://cz.archive.ubuntu.com/ubuntu <http://cz.archive.ubuntu.com/ubuntu>"}}] source=promise
>          > default:main.level1_single
>          >
>         [{"hwraid":{"Suites":["stretch"],"Types":["deb"],"URIs":"https://hwraid.le-vert.net/debian <https://hwraid.le-vert.net/debian>"},"ubuntu":{"Suites":["xenial","xenial-backports","xenial-proposed","xenial-updates","xenial-security"],"URIs":"http://cz.archive.ubuntu.com/ubuntu <http://cz.archive.ubuntu.com/ubuntu>"},"ubuntu-security":{"Suites":["xenial-security"],"URIs":"http://cz.archive.ubuntu.com/ubuntu <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
>         <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]
>         <mailto:[email protected]> | www.surf.nl
>         <http://www.surf.nl> |
> 

-- 
--
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/d51506f4-a70b-837e-1bee-e7adbc699860%40surf.nl.