I have used cbimport to load data from csv to Couchbase Bucket but not sure how to get number data type from CSV to imported as JSON numeric value .
For e.g. by csv data has number like 4036.90 where as after cbimport the JSON I got in my bucket is like below
“Revenue”: “4036.90”
The idea is the JSON to have no string without double quotes ("") : “Revenue”: 4036.90
How to achieve this ?
thanks
Hello @eldorado,
Did you run the cbimport
with the --infer-types
flag?
--infer-types Infer the type of each field (bool, int, float, string)
Perfect . that works … Somehow I overlooked that from command line parameters .
thanks
Hello,
Can someone post here an example command how to use --infer-types flag while importing csv files? I need to declare a field-column as boolean.
Thanks
The idea is the JSON to have no string without double quotes (“”) : “Revenue”: 4036.90
Hi Eldorado,
Just a quick tip: if “revenue” refers to money, you might want to reconsider storing this value as a JSON Number with a decimal component, since many JSON parsers will read this as a floating point number.
Hi @david.nault,
I am trying to use CSV file to import data, Are you able to provide a sample command with --infer-types flag to mark a field as boolean?
Appreciate your help.
Here’s what the documentation for the --infer-types flag says:
By default all values in a CSV files are interpreted as strings. If infer types is set then cbimport will look at each value and decide whether it is a string, integer, or boolean value and put the inferred type into the document.
Note that you’re not telling cbimport the types of the fields – you’re asking it to make an educated guess.
When the --infer-types
option is specified, the following values are converted to JSON Booleans:
t, T, TRUE, true, True, f, F, FALSE, false, False
If the “boolean” value in your CSV file is not one of those, you’re out of luck. You’ll need to either:
A) Pre-process the CSV and convert the boolean field values to one of the recognized values.
B) Post-process the dataset after importing by using N1QL to convert the “boolean” field from a String to a JSON Boolean.
If you decide to go with N1QL, and want help with crafting the N1QL statement, starting a new thread in the N1QL subforum will help the experts see your question.
Thanks,
David
Hello @david.nault,
–infer-types worked well anticipating boolean and integers. How about arrays/lists? How can I represent below array in excel so cbimport via csv can upload it as json array?
“timeNonWorkDays”: [
“SATURDAY”,
“SUNDAY”
],
Thanks
CSV import does not support nested fields. You would need to post-process with N1QL after importing.