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.

struct body parse miss

See original GitHub issue

for example: { “mounts”: [ { “child”: { “path”: “blocks”, “shardFunc”: “/repo/flatfs/shard/v1/next-to-last/2”, “sync”: true, “type”: “flatfs” }, “mountpoint”: “/blocks”, “prefix”: “flatfs.datastore”, “type”: “measure” }, { “child”: { “compression”: “none”, “path”: “datastore”, “type”: “levelds” }, “mountpoint”: “/”, “prefix”: “leveldb.datastore”, “type”: “measure” } ], “type”: “mount” }

parsed struct: type AutoGenerated struct { Mounts []struct { Child struct { Path json:"path" ShardFunc json:"shardFunc" Sync json:"sync" Type json:"type" } json:"child" Mountpoint json:"mountpoint" Prefix json:"prefix" Type json:"type" } json:"mounts" Type string json:"type" }

the second child’s element compression was missed

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mike-hosseinicommented, Mar 8, 2019

This is resolved. Make sure to hard refresh or use your browser’s private/incognito mode to see the changes.

1reaction
mike-hosseinicommented, Mar 7, 2019

I looked into this, the issue is not caused by any of the recent changes.

As a workaround, I renamed elements named child, to child1 and child2 and this is the output I got:

type AutoGenerated struct {
        Mounts []struct {
                Child1 struct {
                        Path string `json:"path"`
                        ShardFunc string `json:"shardFunc"`
                        Sync bool `json:"sync"`
                        Type string `json:"type"`
                } `json:"child1,omitempty"`
                Mountpoint string `json:"mountpoint"`
                Prefix string `json:"prefix"`
                Type string `json:"type"`
                Child2 struct {
                        Compression string `json:"compression"`
                        Path string `json:"path"`
                        Type string `json:"type"`
                } `json:"child2,omitempty"`
        } `json:"mounts"`
        Type string `json:"type"`
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

rust - Can I parse JSON with empty fields with Iron's bodyparser?
Can't parse body to the struct (missing field `address`). Is it possible to make the parser ignore the missing fields? For instance, in...
Read more >
Parsing JSON in a request body with Go - gists · GitHub
Parsing JSON in a request body with Go. ... type Message struct { ... For those of you who are worried about the...
Read more >
Maps vs. Structs which is better for JSON Parsing? | The Startup
Maps or Structs, which should we use to parse JSON, YAML, or any other format? ... This pattern makes our code safe from...
Read more >
Kaitai Struct User Guide
What's even better — even if you're missing the match, as long as you have size specified, you would still parse body of...
Read more >
Go JSON (Un)Marshalling, Missing Fields and Omitempty
Just parse some JSON ¶. You provide field names as annotations. If the JSON payload matches the struct 1:1, it doesn't get more...
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