Answers.Body: <p><code>write_json()</code> is supposed to provide the general way to serialize any data structure for processing/manipulation in the task command script (perhaps leveraging <a href="https://stedolan.github.io/jq/" rel="nofollow noreferrer">jq</a>). Unfortunately, last I heard, <a href="https://github.com/broadinstitute/cromwell/labels/Read%2Fwrite%20JSON%20array%20bug" rel="nofollow noreferrer">Cromwell's implementation doesn't work on some useful cases</a> right now. (Possibly out of date; I haven't tried lately)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-17T16:54:58.400Z
Answers.Text: Just learned this yesterday: in the development version you could try to use `as_map()` and then `write_map()`. However, you have to assume that all the left element in the `Array[Pair[String,String]]` array are unique or `as_map()` will fail.
Answers.UserDisplayName: Giulio Genovese
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-16T20:50:21.967Z
Answers.LastActivityDate: 2020-06-16T20:50:21.967Z
Answers.UserDisplayName: Mike Lin
Body: <p>I have a table containing different metadata information about a set of samples as an Array[Object] and I need to extract a couple of columns from this table and output those two columns into a file that will be read and used by the task. I wanted to know whether I can do this within a task rather than within a workflow, that is, without using the scatter construct which is not allowed inside a task.</p>
  <p>If I zip two arrays I obtain an Array[Pair[String,String]] variable.</p>
  <p>Now if I want to output to file an Array[Array[String]] I can use write_tsv(), if I want to output to file a Map[String,String] I can use write_map().</p>
  <p>But WDL does not let me coerce Array[Pair[String,String]] to either Array[Array[String]] nor Map[String,String] (though I can coerce Map[String,String] to Array[Pair[String,String]]), so neither option is available.</p>
  <p>Is there a solution to this that does not involve the scatter construct?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-16T02:37:16.977Z
Comments.Text: Hi @freeseek, could you please explain the biological relevance behind you informatics WDL question? Are you using BioWDL?
Comments.UserDisplayName: M__
Tags: <wdl>
Title: output Array[Pair[X,Y]] to file inside a WDL task
ThreadText: # output Array[Pair[X,Y]] to file inside a WDL task
  
  (Asked by: username_0 on 2020-06-15)
  
  I have a table containing different metadata information about a set of samples as an Array[Object] and I need to extract a couple of columns from this table and output those two columns into a file that will be read and used by the task. I wanted to know whether I can do this within a task rather than within a workflow, that is, without using the scatter construct which is not allowed inside a task.
  
  If I zip two arrays I obtain an Array[Pair[String,String]] variable.
  
  Now if I want to output to file an Array[Array[String]] I can use write\_tsv(), if I want to output to file a Map[String,String] I can use write\_map().
  
  But WDL does not let me coerce Array[Pair[String,String]] to either Array[Array[String]] nor Map[String,String] (though I can coerce Map[String,String] to Array[Pair[String,String]]), so neither option is available.
  
  Is there a solution to this that does not involve the scatter construct?
  
  **Tags:** wdl
  
  > **Comments:**
  > **username_1**: Hi @freeseek, could you please explain the biological relevance behind you informatics WDL question? Are you using BioWDL?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-06-16. Score: 0
  
  `write_json()` is supposed to provide the general way to serialize any data structure for processing/manipulation in the task command script (perhaps leveraging [jq](https://stedolan.github.io/jq/)). Unfortunately, last I heard, [Cromwell's implementation doesn't work on some useful cases](https://github.com/broadinstitute/cromwell/labels/Read%2Fwrite%20JSON%20array%20bug) right now. (Possibly out of date; I haven't tried lately)
  
  > **Comments:**
  > **username_0**: Just learned this yesterday: in the development version you could try to use `as_map()` and then `write_map()`. However, you have to assume that all the left element in the `Array[Pair[String,String]]` array are unique or `as_map()` will fail.  
  
  ---
  
  