-2
var data = map[string]interface{}{
    "json_received": [
        {
        "ezpOrderId":  "ezp_123",
        "firstName":  "Vasanth",
        "lastName":  "K",
        "orderDesc":  "Sample"
        }
    ] 
    "created_on":  "03-22-2015",
    "status":  "1"
}


result, err := r.Table("order_json").Insert(data).RunWrite(session)

When i m tried to run this program i got the error as "missing operand" after "json_received":[ line.

Please help me to insert the data variable in rethink db via go programming..

Kumar Shanmugam
  • 597
  • 1
  • 11
  • 40
  • Each entry to the map should end with commas including the last one. What is "json_received"? Is it a string? if so you need quotes surrounding it. – Aruna Herath Mar 22 '16 at 10:29

2 Answers2

2

Go does not support json literals like you are trying to do.

Here's a fixed version (on Play).

Notice that for all sub structures, you must declare the type when creating it. You were trying to make json_recieved to be a list of json objects, so I used []map[string]interface{}.

And, as others have pointed out, multi-line map/list literals must have a comma after each line, as in: orderDesc, status.

package main

import "fmt"

func main() {
    var data = map[string]interface{}{
        "json_received": []map[string]interface{}{
            {
                "ezpOrderId": "ezp_123",
                "firstName":  "Vasanth",
                "lastName":   "K",
                "orderDesc":  "Sample",
            },
        },
        "created_on": "03-22-2015",
        "status":     "1",
    }

    fmt.Printf("%#v\n", data)
    //result, err := r.Table("order_json").Insert(data).RunWrite(session)
}
David Budworth
  • 11,248
  • 1
  • 36
  • 45
0

you are missing comma after json_received array

"json_received": [
        {
        "ezpOrderId":  "ezp_123",
        "firstName":  "Vasanth",
        "lastName":  "K",
        "orderDesc":  "Sample"
        }
    ] , //<--
Rafique Mohammed
  • 3,666
  • 2
  • 38
  • 43