FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard.

For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

ToObject

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

ToObject( array )
to_object( array )
ToObject( array )
ToObject( array )
ToObject( 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:

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}
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]
try
{
    Value result = await client.Query(
        ToObject(
            Arr(
                Arr("name", "Dennis"),
                Arr("age", 37)
            )
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(name: StringV(Dennis),age: LongV(37))
System.out.println(
    client.query(
        ToObject(
            Arr(
                Arr(Value("name"), Value("Dennis")),
                Arr(Value("age"), Value(37))
            )
        )
    ).get());
{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!