question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

read_json not being determined as a Map

See original GitHub issue

I’m using read_json to read the contents of a file with a json output, and then immediately trying to access a property on this (through the following minimal example):

version development
task readjson {

  command <<<
      echo '{"out": "Hello, WDL!"}' > out.txt
  >>>

  output {
    String out = read_json('out.txt')["out"]
  }
}

This validates and runs correctly in Cromwell, but in miniWDL I get the following error:

miniwdl run --verbose codetool.wdl
(codetool.wdl Ln 10 Col 18) Not an array
        String out = read_json('out.txt')["out"]
                     ^^^^^^^^^^^^^^^^^^^^

I’ve noticed that you can coerce it to the correct type which will then validate, eg:

version development
task readjson {

  command <<<
      echo '{"out": "Hello, WDL!"}' > out.txt
  >>>

  output {
    Map[String, String] coercedmap = read_json('out.txt')
    String out = coercedmap["out"]
  }
}

But this has the disadvantage that it returns more than what’s required.


Versions:

  • v0.6.3 (through Pip)
  • Latest on Git: miniwdl v0.6.4.dev14

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mlincommented, Apr 3, 2020

@illusional the solution in just-released v0.7.1 is very much along the lines you suggested, but exapts some type unification logic that had existed elsewhere for other purposes. There will probably still be some weird corner cases like non-homogeneity in lists and object value types, as you mention – let us know if you hit anything that clearly ought to work even given that JSON isn’t 100% embeddable in WDL values. Thanks!

1reaction
mlincommented, Mar 27, 2020

Thanks – yea, looks like I punted on this case previously. Will take another look

Read more comments on GitHub >

github_iconTop Results From Across the Web

Read JSON file and map to C# objects - Stack Overflow
I want to read a JSON file and map ...
Read more >
Spark from_json() - Convert JSON Column to Struct, Map or ...
In Spark/PySpark from_json() SQL function is used to convert JSON string from DataFrame column into struct column, Map type, and multiple columns.
Read more >
A Complete Guide to JSON in Golang (With Examples)
This post will describe how to marshal and unmarshal JSON in Go. We will learn how to convert from JSON raw data into...
Read more >
JSON and serialization - Flutter documentation
Unfortunately, jsonDecode() returns a Map<String, dynamic> , meaning that you do not know the types of the values until runtime.
Read more >
How to serialize and deserialize JSON using C# - .NET
Use the library directly, not through a framework such as ASP. ... The preceding examples use type inference for the type being serialized....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found