read_json empty string

lelaginalelagina Member, Broadie

Hello,

I am trying to use read_json function in the wdl:

workflow Test_Read_Json {

Map[String, String] input_json = read_json(File)

call some_task {
input:
parameter= if defined(input_json["parameter1"]) then input_json["parameter1"] else "Some_Other_String"
}}

I have json files that might have an empty strings for input:
{
"parameter1": "",
"parameter2": "Some_String"
}

I try to catch it with if defined() statement.

However it crashes with the following error message:
Call input evaluation failed for some_task
For input string: ""

Tagged:

Best Answer

Answers

  • ChrisLChrisL Cambridge, MAMember, Broadie, Moderator, Dev admin

    Hi @lelagina !

    There are a couple of things I think I spotted in the WDL which may be shorthand while you typed it up here, or may be actual problems.

    Before I write this up as an issue - could you see what happens if you use this with a few changes in the WDL:

    workflow Test_Read_Json {
      File json_file
      Object input_json = read_json(json_file)
    
      call some_task { input:
        parameter = if input_json.parameter1 != "" then input_json.parameter1 else "Some_Other_String"
      }
    }
    
  • lelaginalelagina Member, Broadie

    Hello Chris,

    I tried your example and this is the error that I got:

    Unable to build WOM node for WdlTaskCall 'Test_Read_Json': Cannot build expression for 'Test_Read_Json.some_task.parameter = if input_json.parameter1 != "" then input_json.parameter1 else "Some_Other_String"': The condition of a ternary 'if' must be a Boolean.

  • lelaginalelagina Member, Broadie

    Hello Chris,

    Could you please let me know if you were able to replicate the same issue? I would really appreciate your help with this.

    Thank you,
    Luda.

  • ChrisLChrisL Cambridge, MAMember, Broadie, Moderator, Dev admin

    Hi @lelagina sorry for the delay!

    Something odd is definitely going on here, so I've raised an issue on our GitHub repo to investigate - https://github.com/broadinstitute/cromwell/issues/3829.

    Since I think the second problem you hit might just be a type-checking mistake around object field accesses, this might work if you specify the expected type of parameter1 in an intermediate declaration, ie this might help as a workaround:

    workflow Test_Read_Json {
      File json_file
      Object input_json = read_json(json_file)
      String parameter1 = input_json.parameter1
    
      call some_task { input:
        parameter = if parameter1 != "" then input_json.parameter1 else "Some_Other_String"
      }
    }
    
  • lelaginalelagina Member, Broadie

    Hello Chris,

    Thank you for this suggestion but it will not work in my case as I would need to define large number of this global intermediate variables which I prefer not to do.

    Is there anyway I can cast read_json object to Map[String, String] but still allow to have empty strings?

    Thank you,
    Luda.

Sign In or Register to comment.