-
Hi! I would like to convert a CSV file into JSON line by line. I think I can use the remap function with parse_json for this effect but I'm very noob with this and sure how to make it. My attempts failed. Can someone help me with this simple example of a CSV below? Timestamp;country;duration;quality Edit:
I'm not get any output though... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @rcmv , I think your issue is that your transform is being skipped as you've specified the source, However, I'd also recommend looking at [sources.my_csv_files_id]
type = "file"
include = [ "/home/rcmv2/ftp/" ]
start_at_beginning = true
[transforms.remap]
inputs = ["my_csv_files_id"]
type = "remap"
source = """
csv = require("csv")
row = parse_csv!(.message)
.Timestamp = row[0]
.country = row[1]
.duration = row[2]
.quality = row[3]
"""
[sinks.console]
inputs = ["remap"]
type = "console"
encoding.codec = "json" I didn't test it, but something like that should work. |
Beta Was this translation helpful? Give feedback.
-
I got the bug using the Remap/parse_csv approach. With Lua still does not work. The problem was the csv file delimiter. The delimiter was ';' and I think the parse_csv use by default the delimiter ','.
|
Beta Was this translation helpful? Give feedback.
I got the bug using the Remap/parse_csv approach. With Lua still does not work. The problem was the csv file delimiter. The delimiter was ';' and I think the parse_csv use by default the delimiter ','.
I changed my csv file delimiter from ; to , and now I'm getting the following output:
{"Timestamp":"Timestamp","country":"country","duration":"duration","file":"/home/rcmv2/ftp/sample.csv","host":"ip-172-31-28-49.ec2.internal","message":"Timestamp,country,duration,quality\r","quality":"quality","source_type":"file","timestamp":"2022-09-07T13:52:18.056567562Z"} {"Timestamp":"06/09/2022 10:33","country":"UAE","duration":"7.8470","file":"/home/rcmv2/ftp/sample.csv","host":"ip-172-31-28-49.ec2.…