简体   繁体   中英

JSON int key issue data e2e (invalid character '1' looking for beginning of object key string)

My app uses aerospike to store Map in one of the bins, I am use endly for e2e testing, which uses JSON for data representation:

How do to populate datastore with with JSON where key needs to be an int ? Since json does not allowed int key I am getting the following error: invalid character '1' looking for beginning of object key string

Here is my data workflow (invoked by regression workflow)

@data.yaml

defaults:
  datastore: db1
pipeline:
  register:
    action: dsunit:register
    config:
    driverName: aerospike
    descriptor: "tcp([host]:3000)/[namespace]"
    parameters:
      dbname: db1
      namespace: test
      host: 127.0.0.1
      port: 3000
      dateFormat: yyyy-MM-dd hh:mm:ss
  prepare:
    data:
      action: nop
      init:
      - key = data.db.mydaaset
      - mydaaset = $AsTableRecords($key)
    setup:
      action: dsunit:prepare
      URL: regression/db1/data/
      data: $mydaaset

Here is my use case level data:

@mydaaset.json

[
  {
    "Table": "myDataset",
    "Value": [{
      "id": "$id",
      "created": "$timestamp.yesterday",
      "fc":{
                1191: "$timestamp.yesterday",
                1192: "$timestamp.now",
      }
    }],
   "AutoGenerate": {
      "id": "uuid.next"
    },
    "Key": "${tagId}_myDataset"
  }
]

In your example @mydaaset.json file is invalid JSON, thus you getting

'invalid character '1' looking for beginning of object key string' 

parsing error

In order to pre-seed your use case test data in aerospike with map[int]int bin you can use AsInt UDF

@mydaaset.json

[
  {
    "Table": "myDataset",
    "Value": [{
      "id": "$id",
      "created": "$timestamp.yesterday",
      "fc":{
                "$AsInt(1191)": "$timestamp.yesterday",
                "$AsInt(1192)": "$timestamp.now",
      }
    }],
   "AutoGenerate": {
      "id": "uuid.next"
    },
    "Key": "${tagId}_myDataset"
  }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM