Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using MarshallJSON() on objects yields strange results #404

Open
mustafaakin opened this issue Mar 6, 2024 · 0 comments
Open

Using MarshallJSON() on objects yields strange results #404

mustafaakin opened this issue Mar 6, 2024 · 0 comments

Comments

@mustafaakin
Copy link

ctx := v8.NewContext()
val, _ := ctx.RunScript("result = { name: 'mustafa'}; result", "main.js")
b, _ := val.MarshalJSON()
fmt.Println(val, string(b))

The outputs are:

[object Object] {"name":"mustafa"}

However when I run the following output does not care about my object and when I define another field its just an error

{ name: 'mustafa'} => mustafa "mustafa"
{name: 'mustafa', age: 32} => SyntaxError: Unexpected token ':'

Not sure what's going on here but it works on arrays without a problem

[1, false, 3.14, 'mustafa', {name: 'mustafa', age : 30}] 
=>
1,false,3.14,mustafa,[object Object] [1,false,3.14,"mustafa",{"name":"mustafa","age":30}]

Any pointers would be great. When I type the object definition to Chrome console or Node REPL it does not complain, so what is different here? I'm building an template execution engine and current parsing code is a quick hack and not ideal. https://github.com/mustafaakin/templ8go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant