Russ Wilkie
Russ Wilkie

Reputation: 143

Is it bad practice to skip encoding a JSON file if it's just going to be decoded?

This may sound like a silly question, but back when I was interning at a web company I was put on a PHP-Based project that involved scraping web data to be stored into a database table. The process involved writing a script to scrape the data, parse specific information to a JSON file, then writing another script that will take the JSON data and store it into a database.

Recently I started working on an academic project that uses functionality similar to what I learned from my internship and started to wonder if it would be wise to follow suit with the process used for that internship project.

I don't really know why I was required to use json_encode for an associative array, save it as a JSON file, then have another script that took that file and decoded it before inserting it to the database. I feel it would be more efficient to just skip creating the JSON file completely.

Are there any benefits to doing this as opposed to just directly merging the two scripts so I skip the encoding and decoding part all together? Would it be better practice for my programming career if I separated the code into different scripts?

Upvotes: 0

Views: 138

Answers (1)

Lexxusss
Lexxusss

Reputation: 552

I guess that during your internship in web company you was need to encode-decode data for passing this data to frontend client (javascript-code) and then in the opposite direction (javascript sends some json data to server).

So, if in your current project you don't see any reason of encoding data - so do not do this ! )

Encoded data is very helpful in some cases, for instance you can save this data directly to database like a string OR you can send this data to browser in order to be parsed by javascript.

So, again: if you don't need to parse/convert/encode data - you should not to do this.

Upvotes: 1

Related Questions