Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
csvjson library / gem - read tabular data in the CSV <3 JSON format, that is, comma-separated values CSV (line-by-line) records with javascript object notation (JSON) encoding rules
CSV <3 JSON is a Comma-Separated Values (CSV) variant / format / dialect where the line-by-line records follow the JavaScript Object Notation (JSON) encoding rules. It's a modern (simple) tabular data format that includes arrays, numbers, booleans, nulls, nested structures, comments and more. Example:
# "Vanilla" CSV <3 JSON
1,"John","12 Totem Rd. Aspen",true
2,"Bob",null,false
3,"Sue","Bigsby, 345 Carnival, WA 23009",false
or
# CSV <3 JSON with array values
1,"directions",["north","south","east","west"]
2,"colors",["red","green","blue"]
3,"drinks",["soda","water","tea","coffe"]
4,"spells",[]
For more see the official CSV <3 JSON Format documentation »
txt <<=TXT
# "Vanilla" CSV <3 JSON
1,"John","12 Totem Rd. Aspen",true
2,"Bob",null,false
3,"Sue","Bigsby, 345 Carnival, WA 23009",false
TXT
records = CsvJson.parse( txt ) ## or CSV_JSON.parse or CSVJSON.parse
pp records
# => [[1,"John","12 Totem Rd. Aspen",true],
# [2,"Bob",nil,false],
# [3,"Sue","Bigsby, 345 Carnival, WA 23009",false]]
# -or-
records = CsvJson.read( "values.json.csv" ) ## or CSV_JSON.read or CSVJSON.read
pp records
# => [[1,"John","12 Totem Rd. Aspen",true],
# [2,"Bob",nil,false],
# [3,"Sue","Bigsby, 345 Carnival, WA 23009",false]]
# -or-
CsvJson.foreach( "values.json.csv" ) do |rec| ## or CSV_JSON.foreach or CSVJSON.foreach
pp rec
end
# => [1,"John","12 Totem Rd. Aspen",true]
# => [2,"Bob",nil,false]
# => [3,"Sue","Bigsby, 345 Carnival, WA 23009",false]
Yes, the reader / parser includes Enumerable
and runs on each
.
Use new
or open
without a block
to get the enumerator (iterator).
Example:
csv = CsvJson.new( "1,2,3" ) ## or CSV_JSON.new or CSVJSON.new
it = csv.to_enum
pp it.next
# => [1,2,3]
# -or-
csv = CsvJson.open( "values.json.csv" ) ## or CSV_JSON.open or CSVJSON.open
it = csv.to_enum
pp it.next
# => [1,"John","12 Totem Rd. Aspen",true]
pp it.next
# => [2,"Bob",nil,false]
Yes, you can. Use the CsvHash
from the csvreader library / gem
if the first line is a header (or if missing pass in the headers
as an array) and you want your records as hashes instead of arrays of strings.
Example:
txt <<=TXT
"id","name","address","regular"
1,"John","12 Totem Rd. Aspen",true
2,"Bob",null,false
3,"Sue","Bigsby, 345 Carnival, WA 23009",false
TXT
records = CsvHash.json.parse( txt )
pp records
# => [{"id": 1,
# "name": "John",
# "address": "12 Totem Rd. Aspen",
# "regular": true},
# {"id": 2,
# "name": "Bob",
# "address": null,
# "regular": false},
# ... ]
For more see the official CsvHash documentation in the csvreader library / gem »
The csvjson
scripts are dedicated to the public domain.
Use it as you please with no restrictions whatsoever.
Send them along to the wwwmake forum. Thanks!
FAQs
Unknown package
We found that csvjson demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.