The same records can wear two different shapes in JSON, and the difference decides whether an import works. Pack your contacts as an array of objects and the file is a list: ordered, looped over, one object per record. Pack them as a keyed object and the file is a map: each record sits under a unique key, usually an ID, and is fetched by looking that key up. Neither shape is better. Each is right for one kind of reader and wrong for the other.
This guide explains how the two shapes behave, how to tell which one your importer wants, and where the free CSV to JSON Converter on Ovatly fits: it produces the array, and knowing that upfront saves a wasted conversion.
Contents
- Quick answer
- The two shapes, side by side
- Looping over vs looking up
- Order and duplicates: the two real differences
- What the converter produces
- From CSV to the shape you need, step by step
- Worked example: when a key collides
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Decide from the importer's documentation, not from taste. If the importer reads a list of records, it wants an array of objects. If it updates records by ID, it may want a keyed object. The CSV to JSON Converter outputs arrays only: an array of objects with the header on, an array of arrays with it off. So convert to the array first. If your importer wants the keyed shape, the reshape is a separate step afterwards, done by hand for a short list or in code for a long one.
The two shapes, side by side
Take two small records. As an array of objects, they look like this:
[
{ "name": "Ana", "age": "31" },
{ "name": "Ben", "age": "28" }
]
The same two records as a keyed object, keyed here by name so the shape is easy to see:
{
"Ana": { "age": "31" },
"Ben": { "age": "28" }
}
The information is identical. What changed is how a reader reaches it. In the array, a record is found by its position. In the keyed object, a record is found by naming its key. In real files the key is normally an ID field rather than a name, for reasons the duplicates section makes concrete.
Looping over vs looking up
The array suits a consumer that processes every record in turn: an import, a feed, a report, a sync. The reader starts at the first record and works through to the last, and the shape says exactly that: here is a list of things, take them all.
The keyed object suits a consumer that fetches single records by identity: a cache, a lookup table, a store that updates one entry by its ID. The reader never scans the file; it asks for one key and gets one record. Picture how your importer actually reads, and the shape it wants is usually obvious.
Order and duplicates: the two real differences
Order first. An array preserves the order of your CSV rows: first row, first record. A keyed object is a map, and a map makes no promise about sequence; readers take records by key, not by position. If row order carries meaning, the array keeps it and the keyed object sets it aside.
Duplicates are the sharper difference. An array tolerates them: two records with the same name, or even the same ID, sit side by side and both survive. A keyed object cannot hold two records under one key. The second record with that key overwrites the first, silently, with no error. A keyed shape is only safe when the key is genuinely unique for every record.
What the converter produces
The CSV to JSON Converter produces arrays only. With the header option on, you get an array of objects keyed by your header names. With it off, you get an array of arrays. Every value stays a string in either case, and the conversion runs locally in your browser.
If the keyed shape is what you need, the route is: convert first, then reshape. Pick the field that is unique for every record, and rebuild the output as an object with that field's value as each key and the rest of the record as its value. For a handful of records that is a few minutes by hand; for a long list it is a small job in code.
From CSV to the shape you need, step by step
- Read the importer's documentation, or export a sample file from the app. The top level of the sample settles the question: a list in square brackets is an array, a map in curly braces is a keyed object.
- Convert your CSV with the CSV to JSON Converter, header on, so you have a clean array of objects.
- If the importer wants the array, you are done: import the file as it stands.
- If it wants a keyed object, choose the unique ID field, check that no two records share its value, and reshape the array into a map keyed by it.
Worked example: when a key collides
Suppose your CSV holds two different contacts who happen to share a name:
name,age
Ana,31
Ana,28
As an array of objects, both records survive the conversion, side by side, and an importer reads two contacts. Nothing is lost, because a list does not ask its records to be unique.
Now reshape that output into a keyed object keyed by name. The first Ana is written under the key "Ana", and then the second Ana is written under the same key, replacing her. The result holds one record, and the file gives no sign that anything went missing. This is why real keyed files use an ID built to be unique, and why keying by name, email or phone is an accident waiting for its second occurrence.
Limitations and honest tradeoffs
The converter cannot make this decision for you, and it cannot produce the keyed shape at all. It also cannot warn you when the field you plan to reshape by is not unique; uniqueness is a property of your data, and only you can check it. And values stay strings in both shapes, so an importer that demands a numeric JSON type for a field will not get one from this conversion, whichever shape you choose.
Common mistakes
- Choosing the keyed shape because it looks tidier. Shape is a contract with the importer, not a style preference.
- Keying by a field that is not unique. Names repeat. The moment two records share the key, one of them is gone.
- Assuming a failed import means the data is wrong. Often the records are fine and only the packaging is wrong. Check the top level of the file first.
- Reshaping before checking. Convert once, read the importer's sample file, and reshape only if the keyed shape is actually required.
FAQs
What is the difference between an array of objects and a keyed object? An array of objects is an ordered list of records, reached by position and usually looped over. A keyed object is a map: each record sits under a unique key, usually an ID, and is reached by looking that key up directly.
Can the CSV to JSON Converter produce a keyed object? No. It produces arrays only: an array of objects with the header on, or an array of arrays with it off. If your importer wants a keyed object, convert to the array first and reshape it afterwards, by hand for a short list or in code for a long one.
Which shape do importers usually want? Imports of a list of records, contacts, products or rows, generally expect an array of objects: the file is a list of things. Importers that update existing records by ID sometimes ask for a keyed object instead. The importer's documentation or sample file is the authority, not preference.
What happens to duplicate keys in a keyed object? They cannot coexist. If two records are keyed by the same value, the second overwrites the first when the object is built or read, and the first record is lost without an error. An array has no such risk: duplicates simply sit side by side.
Does a keyed object keep the order of my CSV rows? Order is not what a keyed object is for: it is a map, read by key rather than by position, so sequence is not part of its meaning. If the order of your records matters to the importer, the array of objects is the shape that preserves it.
Conclusion
If your importer reads a list, give it the array; if it reads by ID, give it the map, and let the importer's documentation make the call. The CSV to JSON Converter produces the array of objects from your CSV in one step, and the keyed shape, when you truly need it, is a deliberate reshape afterwards. Our companion guide on converting a contacts CSV into JSON for an app import walks through the conversion itself, headers, strings and all. For more in this series, see the Data and JSON Tools guides.
References
- RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format: https://www.rfc-editor.org/rfc/rfc8259
- RFC 4180, Common Format and MIME Type for Comma-Separated Values (CSV) Files: https://www.rfc-editor.org/rfc/rfc4180