1

I have an object that is equivalent to this BERT (wrapped for legibility):

{"Hello",[{1,"john","john123"},{2,"Michale","michale123"}]} 

in Node:

var S = Bert.bytes_to_string([131,104,2,107,0,5,72,101,108,108,111,108,0,0,0,2,104,3,97,1,107,0,4,106,111,104,110,107,0,7,106,111,104,110,49,50,51,104,3,97,2,107,0,7,77,105,99,104,97,108,101,107,0,10,109,105,99,104,97,108,101,49,50,51,106]);
var Obj = Bert.decode(S);
console.log(obj);

I can see in console as below.

{
  '0': {
    type: 'bytelist',
    value: 'Hello',
    toString: [ Function ],
    repr: [ Function ]
  },
  '1': [
    {
      '0': 1,
      '1': [ Object ],
      '2': [ Object ],
      type: 'tuple',
      length: 3,
      value: [ Object ],
      repr: [ Function ],
      toString: [ Function ]
    },
    {
      '0': 2,
      '1': [ Object ],
      '2': [ Object ],
      type: 'tuple',
      length: 3,
      value: [ Object ],
      repr: [ Function ],
      toString: [ Function ]
    }
  ],
  type: 'tuple',
  length: 2,
  value: [
    {
      type: 'bytelist',
      value: 'Hello',
      toString: [ Function ],
      repr: [ Function ]
    },
    [
      [ Object ],
      [ Object ]
    ]
  ],
  repr: [ Function ],
  toString: [ Function ]
}

How to get the output as

{"Hello",[{1,"john","john123"},{2,"Michale","michale123"}]} 

from above obj?

Jonas
  • 121,568
  • 97
  • 310
  • 388

1 Answers1

3

use

Obj['0'].value

to obtain the string "hello" and

Obj['1'].forEach(function(el){
  var fst = el['0'] //1,2
  var snd = el['1'].value //John,Mihcale
  var thd = el['2'].value  //john123,michale123
})

You only read "[Object]" because console.log does not go deep in the object hierarchy, if you want to visualize all the properties, try something like:

console.log(require('util').inspect(Obj,false,100))
cheng81
  • 2,434
  • 2
  • 21
  • 18
  • 1
    Please notice that the erlang tuple format is not a valid JSON format; that is, JSON does not have the notion of "tuple", only of list and associative arrays, thus "{foo,bar,baz}" is valid erlang, but not valid JSON. You could instead return a JSON object like: "{'hello':[{'name':'john','pwd':'john123'},{'name':'michale','pwd':'michale123'}]}" – cheng81 Dec 16 '11 at 12:34