Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to build a nested, dynamic JSON in Go

package main

import (
    "encoding/json"
    "fmt"
)

type Point struct {
    X, Y int
}

func main() {
    m := map[string]any{}
    var singleCoordinate bool
    if singleCoordinate {
        m["Coordinates"] = []float32{1, 2}
    } else {
        m["Coordinates"] = []Point{{X: 1, Y: 2}, {X: 2, Y: 2}}
    }
    data, err := json.Marshal(m)
    fmt.Println(string(data), err)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: vue custom event validation 
Javascript :: flatten a nested json 
Javascript :: generar numero aleatorio en un rango 
Javascript :: Node.js with Express: Importing client-side javascript using script tags in Jade views 
Javascript :: Transfer file to server using rsync 
Javascript :: ant design rtl 
Javascript :: insert image in jsp page 
Javascript :: filter number from string in javascript 
Javascript :: read excel file npm 
Javascript :: nodejs passport starter template with username and password 
Javascript :: how to set socket io into global express 
Javascript :: Create A Class Using JavaScript 
Javascript :: phaser asteroid movement 
Javascript :: function listview list grud abnAlhaj 
Javascript :: In Self Invoking Functions, the This Below Console.Logs The Created Object 
Javascript :: select next occurrence visual studio 
Javascript :: What Is A Closure: Informal Explanation 
Javascript :: repeated click onchange javascript 
Javascript :: dayofyear mongodb 
Javascript :: Hardhat deploy sample js code 
Javascript :: javascrit loop array 
Javascript :: js beutify node.js 
Javascript :: Backbone View Event 
Javascript :: Prevent HTTP Parameter Polution in NodeJS 
Javascript :: how to check if a div tag contains child 
Javascript :: how to run json server 
Javascript :: javascript get max value in array of objects 
Javascript :: change your favicon in javascript 
Javascript :: switch 
Javascript :: jquery tab click event 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =