ToObject

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

ToObject( array )
ToObject( array )
to_object( array )
ToObject( array )

Description

The ToObject function converts an Array of arrays, containing field names and values, into an Object, if possible.

If array cannot be converted into an object, an "invalid argument" error is returned.

Parameters

Parameter Type Definition and Requirements

array

Array

An Array of Arrays containing field names and values.

Returns

An Object composed of the fields names and values from array.

Examples

The following query converts an array into an object:

result, err := client.Query(
	f.ToObject(
		f.Arr{
			f.Arr{"name", "Dennis"},
			f.Arr{"age", 37},
		}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[age:37 name:Dennis]
client.query(
  q.ToObject([['name', 'Dennis'], ['age', 37]])
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{ name: 'Dennis', age: 37 }
result = client.query(
  q.to_object([['name', 'Dennis'], ['age', 37]])
)
print(result)
{'name': 'Dennis', 'age': 37}
ToObject([['name', 'Dennis'], ['age', 37]])
{ name: 'Dennis', age: 37 }
Query metrics:
  •    bytesIn:  44

  •   bytesOut:  39

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 2ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!