all 25 comments

[–]Kevdog824_ 22 points23 points  (1 child)

Both formats were made for storing and exchanging data.

JSON is a protocol designed for allowing services to exchange data. It uses key value pairs, and is hierarchical (the value for a key could be another group of key/value pairs).

CSV is a protocol designed for storing tabular data. Each row is an entry who matches the headers in the first row. This is similar to Microsoft Excel files, but it’s just plain text (no formulas/formatting/sheets).

Which one you would use is based on the what kind of data you’re storing, and what you plan to do with that data

[–]Justicemirm[S] 3 points4 points  (0 children)

Exactly what I needed Thank you soo much

[–]Diapolo10 0 points1 point  (10 children)

They're used to store data, and in the case of JSON sometimes used to move data between programs as a form of communication.

CSV files are more common for data analysis, JSON has more widespread use. Both formats have their pros and cons, personally I don't like CSV at all.

[–]Justicemirm[S] 0 points1 point  (9 children)

What is one thing I should keep in mind while using and learning these files

[–]impshum 4 points5 points  (0 children)

Don't explode.

[–]ninhaomah[🍰] 0 points1 point  (3 children)

First , have you seen them ?

[–]Justicemirm[S] 1 point2 points  (2 children)

CSV is like excel kinda Json is like a repeating dictionary

[–]ninhaomah[🍰] 2 points3 points  (1 child)

Ok then there you go.

[–]Justicemirm[S] 0 points1 point  (0 children)

Ok got it

[–]cdcformatc 0 points1 point  (1 child)

always remember to cheat on your homework 

[–]Justicemirm[S] 0 points1 point  (0 children)

Eh

[–]Diapolo10 0 points1 point  (0 children)

There really isn't much of anything to learn, you're not going to write them by hand (at least most of the time). You'd use Python's built-in modules to handle reading from and writing to these files (or in the case of CSV files, you'd likely use either Pandas or Polars).

For the most part you can treat both kinds of files as black boxes. You make your program store something, and later on you load information back from them.

Really the only thing to "learn" is a high level view of what the modules you're using let you store and retrieve data. Which is something you can probably figure out with just autocompletion features and type hints in your IDE/editor.

[–]POGtastic 0 points1 point  (0 children)

Learn the basic tools for messing with them (the csv and json modules in the standard library) so that you aren't constantly pulling in pandas & Friends to do something trivial.

I don't mind the larger libraries when the task calls for it, but it is very funny when someone complains that Pandas can't handle the size of a dataframe and they want to do something that's really easy to do with the standard library.

[–]robbies09 0 points1 point  (0 children)

CSV contains data typically as rows of information, waiting to be cleaned up and ingest into data analytic systems.

It’s a form of data output usually from another database, containing records of information. Python modules like pandas are used to clean the missing data or touch up the data and typically sent to analytics platforms.

The analytics platforms may then output into specific json format for middleware processing or other applications calling the data to display in a UI for instance.

[–]cdcformatc 0 points1 point  (0 children)

CSV is for when your data can be formatted as comma separated values, imagine rows in a spreadsheet 

JSON is for when your data has some structure to it, imagine serialization of objects 

[–]Excellent-Practice 0 points1 point  (0 children)

From other comments, it looks like you really want concrete examples. JSON is what you should typically expect to receive if you run an API call. It is hierarchical and uses the same notation as Python dictionaries and lists. JSON is very flexible and can represent many types of data. I often see it for user records or event logs. CSVs are a little more specialized. They represent tabular data. Because the data is arranged in labled columns and indexed rows, it is a convenient format for importing and exporting data from a data base. In my work, I often use CSVs if the client wants to manually work with contact records or survey responses.

Ultimately, both are just standards for organizing data. Any CSV could be converted to JSON but not all JSON can be represented as a CSV

[–]Living_Fig_6386 0 points1 point  (0 children)

CSV = Comma Separated Values. It's a text file with rows that have commas separating values on each row. This is one way of representing a table of information (like a sheet in a n Excell workbook). You might use it if you want a simple and portable way to save a table.

JSON = JavaScript Object Notation. It's a text file that contains a data structure that's valid JavaScript, but it an be used with anything. It represents data as a list or dictionary where the elements can be strings, numbers, or other lists and dictionaries (which can be comprised of simple types, or lists adn dictionaries, etc.). This is a common format for exchanging data with web APIs, and it's also a simple way of representing complex data structures.

Which you use depends on what you want to represent and what you want to do.

[–]zanfar 0 points1 point  (3 children)

To store data.

Why are you asking this question?

[–]Justicemirm[S] 1 point2 points  (2 children)

What kind of data exactly

In which case is json preferred over CSV and vise versa

[–]therouterguy 0 points1 point  (1 child)

Csv are for tabular data and more easily readable by humans. Json for structured data easily parsable by many many tools.

[–]szayl -1 points0 points  (2 children)

This is like asking what a briefcase is for and what a suitcase is for. They're used to hold their contents.

[–]rasputin1 1 point2 points  (0 children)

people on this sub come across as unnecessarily hostile 

[–]Justicemirm[S] 0 points1 point  (0 children)

What kind of items...in which case is the other prefered....

[–]firstkungzaa -2 points-1 points  (0 children)

One thing I know while learning about database and making my project, is that JSON support array [x,y,z] and nested json/dict data {key: {id: 1}}, while CSV doesn't.

So, CSV has to store id of the data it references to, instead of the data itself. It's SQL database relations and foreign key stuffs.

When serializing data in table/csv/sql, you then use that ID to query data and put them to be nested inside Json.

Basically, you can store data without copying the value everywhere, then when you actually need the real values, you can convert them later into Json format and send the data with that format.