Save json multiple in for loop

144 views
Skip to first unread message

Khushbu Kella

unread,
Jun 7, 2022, 3:50:12 AM6/7/22
to Jsonnet
I have a jsonnet that iterates on a list. 
I want to save each list in a different file. but in the for loop, I am not able to use the save command how to save that in different JSON. 
for example
{
  local check = {
  [config]  :{
local  a= std.get(checkConfig, config),
local mergeConfig= std.mergePatch(a, dynamicConfig),
 Config:std.mergePatch(mergeConfig,staticConfig),
  },
    for config in std.objectFields(checkConfig)  
},


I want to save Config (Config:std.mergePatch(mergeConfig,staticConfig),) each config in a different file.. is there any possibility to do that.

Thanks,
Khushbu

Dave Cunningham

unread,
Jun 7, 2022, 8:13:01 AM6/7/22
to Khushbu Kella, Jsonnet
You need to use the comprehension to define the filenames as fields of the object you're building:

jsonnet -m . -e "local files = ['a.txt', 'b.txt']; { [file]: 'The content of %s' % file for file in files }"

Also if you know that config is a field of checkConfig then you can just do checkConfig[config], you don't need std.get.

I think what you want to write is something like:

{
  [filename]: { Config: std.mergePatch(std.mergePatch(checkConfig[filename], dynamicConfig), staticConfig) }
  for filename in std.objectFields(checkConfig)
}


This message and its attachments are confidential (or legally privileged) information and are meant solely for the addressee of such message. Any unauthorized use of the message / its attachments is strictly prohibited.

--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/0be8de43-5c56-4160-8d65-41633a56460en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages