Closed suntong closed 5 years ago
@suntong As mentioned in my comment https://github.com/mholt/json-to-go/issues/35#issuecomment-469889548, this is not a regression.
Also upon further investigation, I noticed that it works fine when I tested it using Node.js but not Google Chrome. This is the output I got:
type AutoGenerated struct {
ID string `json:"id"`
Version string `json:"version"`
Name string `json:"name"`
URL string `json:"url"`
Tests [] `json:"tests"`
Suites [] `json:"suites"`
Urls []interface{} `json:"urls"`
Plugins []interface{} `json:"plugins"`
}
type Commands struct {
ID string `json:"id"`
Comment string `json:"comment"`
Command string `json:"command"`
Target string `json:"target"`
Targets []interface{} `json:"targets"`
Value string `json:"value"`
}
type Tests struct {
ID string `json:"id"`
Name string `json:"name"`
Commands [] `json:"commands"`
}
type Suites struct {
ID string `json:"id"`
Name string `json:"name"`
PersistSession bool `json:"persistSession"`
Parallel bool `json:"parallel"`
Timeout int `json:"timeout"`
Tests []string `json:"tests"`
}
So I think this issue can be closed. The solution I purpose is either to wait till it becomes available at https://mholt.github.io/json-to-go/ or clone the repository and run the code with Node.js.
Here is how to run it locally using Node.js:
app.js
file in the same location as the json-to-go.js
data.json
file with your JSON dataapp.js
// app.js
const jsonToGo = require('./json-to-go')
var goCode = new jsonToGo( require('fs').readFileSync("./data.json", "utf8") )
console.log(goCode.go)
6. Run `node app.js` from the terminal in the same folder
Sure. thanks for all the helps.
Are these output correct?
Tests [] `json:"tests"`
Suites [] `json:"suites"`
They are missing the variable names (or type definitions) in my view.
Confirmed, I got:
syntax error: unexpected literal `json:"tests"`, expecting type
syntax error: unexpected literal `json:"suites"`, expecting type
No, the output doesn't look correct. I will look into it.
The following json works for previous anonymous struct, but not the current non-anonymous structs. I just get
undefined
.Would you double-check please? Thx!
Originally posted by @suntong in https://github.com/mholt/json-to-go/issues/35#issuecomment-469879323