Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 20,944
» Latest member: NeroSx
» Forum threads: 21,958
» Forum posts: 22,925

Full Statistics

Online Users
There are currently 2058 online users.
» 0 Member(s) | 2053 Guest(s)
Applebot, Baidu, Bing, Facebook, Google

Latest Threads
[WoW Retail News] Season ...
Forum: World of Warcraft
Last Post: xSicKxBot

» Replies: 0
» Views: 11
[DevBlog MS] Build Your O...
Forum: C#, Visual Basic, & .Net Frameworks
Last Post: xSicKxBot

» Replies: 0
» Views: 14
[Steam Release] Killsquad...
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 9
How to play Squirrel Girl...
Forum: PC Discussion
Last Post: xSicKxBot

» Replies: 0
» Views: 12
[WoW Retail News] Paladin...
Forum: World of Warcraft
Last Post: xSicKxBot

» Replies: 0
» Views: 14
[Steam Release] Rec Room
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 17
[DevBlog MS] Share your ....
Forum: C#, Visual Basic, & .Net Frameworks
Last Post: xSicKxBot

» Replies: 0
» Views: 22
[Steam Release] Clone Dro...
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 20
[WoW Retail News] Noctina...
Forum: World of Warcraft
Last Post: xSicKxBot

» Replies: 0
» Views: 27
[DevBlog MS] Use C# union...
Forum: C#, Visual Basic, & .Net Frameworks
Last Post: xSicKxBot

» Replies: 0
» Views: 28

 
  [Tut] Convert PHP CSV to JSON
Posted by: xSicKxBot - 08-12-2023, 08:48 AM - Forum: PHP Development - No Replies

[Tut] Convert PHP CSV to JSON

by Vincy. Last modified on March 17th, 2023.

JSON format is a widely used format while working with API development. Most of the existing API responses are in JSON format.

Converting CSV content into a JSON format is simple in PHP. In this article, we will see different methods of achieving this conversion.

Quick example


<?php $csvFileContent= file_get_contents("animals.csv");
// Converts the CSV file content into line array $csvLineArray = explode("\n", $csvFileContent);
// Forms row results in an array format
$result = array_map("str_getcsv", $csvLineArray);
$jsonObject = json_encode($result);
print_r($jsonObject);
?>

The above quick example in PHP converts the CSV file content into JSON with few lines of code.

  1. First, it reads the .csv file content using the PHP file_get_contents() function.
  2. It explodes the CSV row by the new line (\n) escape sequence.
  3. Then, it iterates the line array and reads the line data of the CSV row.
  4. Finally, the resultant CSV row array is converted to JSON using the json_encode() function.

In step 3, the iteration happens with a single line of code. This line maps the array to call  PHP str_getcsv to parse and convert the CSV lines into an array.

When we saw the methods of reading a CSV file, we created an example using str_getcsv function.

The below input file is saved and used for this PHP example.

Input CSV

Id,Name,Type,Role
1,Lion,Wild,"Lazy Boss"
2,Tiger,Wild,CEO
3,Jaguar,Wild,Developer

Output JSON

This PHP quick example displays the below JSON output on the browser.

[["Id","Name","Type","Role"],["1","Lion","Wild","Lazy Boss"],["2","Tiger","Wild","CEO"],["3","Jaguar","Wild","Developer"]]

In the following sections, we will see two more examples of converting CSV files into JSON.

  1. Method 2: Convert CSV (containing header) into a JSON (associating the column=>value pair)
  2. Method 3: Upload a CSV file and convert it into JSON

upload and convert csv to json

Method 2: Convert CSV (containing header) into a JSON (associating the column=>value pair)


This example uses a CSV string as its input instead of a file.

It creates the header column array by getting the first row of the CSV file.

Then, the code iterates the CSV rows from the second row onwards. On each iteration, it associates the header column and the iterated data column.

This loop prepares an associative array containing the CSV data.

In the final step, the json_encode() function converts the associative array and writes it into an output JSON file.

<?php
$csvString = "Id,Name,Type,Role
1,Lion,Wild,Boss
2,Tiger,Wild,CEO
3,Jaguar,Wild,Developer"; $lineContent = array_map("str_getcsv", explode("\n", $csvString)); $headers = $lineContent[0];
$jsonArray = array();
$rowCount = count($lineContent);
for ($i=1;$i<$rowCount;$i++) { foreach ($lineContent[$i] as $key => $column) { $jsonArray[$i][$headers[$key]] = $column; }
} header('Content-type: application/json; charset=UTF-8');
$fp = fopen('animals.json', 'w');
fwrite($fp, json_encode($jsonArray, JSON_PRETTY_PRINT));
fclose($fp);
?>

Output – The animal.json file


This is the output written to the animal.json file via this PHP program.

{ "1": { "Id": "1", "Name": "Lion", "Type": "Wild", "Role": "Boss" }, "2": { "Id": "2", "Name": "Tiger", "Type": "Wild", "Role": "CEO" }, "3": { "Id": "3", "Name": "Jaguar", "Type": "Wild", "Role": "Developer" }
}

Method 3: Upload a CSV file and convert it into JSON


Instead of using a fixed CSV input assigned to a program, this code allows users to choose the CSV file.

This code shows an HTML form with a file input to upload the input CSV file.

Once uploaded, the PHP script will read the CSV file content, prepare the array, and form the JSON output.

In a previous tutorial, we have seen how to convert a CSV into a PHP array.

upload-and-convert-csv-to-json.php

<?php
if (isset($_POST["convert"])) { if ($_FILES['csv_file_input']['name']) { if ($_FILES['csv_file_input']["type"] == 'text/csv') { $jsonOutput = array(); $csvFileContent = file_get_contents($_FILES['csv_file_input']['tmp_name']); $result = array_map("str_getcsv", explode("\n", $csvFileContent)); $header = $result[0]; $recordCount = count($result); for ($i = 1; $i < $recordCount; $i++) { // Associates the data with the string index in the header array $data = array_combine($header, $result[$i]); $jsonOutput[$i] = $data; } header('Content-disposition: attachment; filename=output.json'); header('Content-type: application/json'); echo json_encode($jsonOutput); exit(); } else { $error = 'Invalid CSV uploaded'; } } else { $error = 'Invalid CSV uploaded'; }
}
?>
<!DOCTYPE html>
<html> <head> <title>Convert CSV to JSON</title> <style> body { font-family: arial; } input[type="file"] { padding: 5px 10px; margin: 30px 0px; border: #666 1px solid; border-radius: 3px; } input[type="submit"] { padding: 8px 20px; border: #232323 1px solid; border-radius: 3px; background: #232323; color: #FFF; } .validation-message { color: #e20900; } </style>
</head>
<body> <form name="frmUpload" method="post" enctype="multipart/form-data"> <input type="file" name="csv_file_input" accept=".csv" /> <input type="submit" name="convert" value="Convert"> <?php if (!empty($error)) { ?> <span class="validation-message"><?php echo $error; ?></span> <?php } ?> </form>
</body>
</html>

Output:

This program writes the output JSON into a file and downloads it automatically to the browser.

Note: Both methods 2 and 3 require CSV input with a header column row to get good results.
output json file
Download

↑ Back to Top



https://www.sickgaming.net/blog/2023/03/...v-to-json/

Print this item

  (Indie Deal) HOPA Wave Bundle, Baldur's Gate II, Ghostbusters & Summer Sale
Posted by: xSicKxBot - 08-12-2023, 08:47 AM - Forum: Deals or Specials - No Replies

(Indie Deal) HOPA Wave Bundle, Baldur's Gate II, Ghostbusters & Summer Sale

It's time to ride the indie wave of Hidden-Object Puzzle Adventure video games. [www.indiegala.com]
Baldur's Gate II: Enhanced Edition
[www.indiegala.com]
Baldur's Gate II: Enhanced Edition is the beloved RPG classic, enhanced for modern adventurers.
https://www.youtube.com/watch?v=PCBpM2W8A84&ab_channel=Beamdog
TheGameCreators Sale, up to 75% OFF
[www.indiegala.com]
Ghostbusters: The Video Game Remastered
[www.indiegala.com]
The beloved and critically acclaimed Ghostbusters video game is back! Join the Ghostbusters team, fight monsters, capture ghosts, search for artifacts and have a blast destroying almost everything around you in this Remastered version of the third-person adventure Ghostbusters: The Video Game.
https://www.youtube.com/watch?v=CUHjGQy0XDs&ab_channel=SaberInteractive
Best of Bandai August Sale NCSA ONLY, up to 90% OFF
[www.indiegala.com]


https://steamcommunity.com/groups/indieg...9000556327

Print this item

  (Free Game Key) Train Valley 2 - Free Epic Games Game
Posted by: xSicKxBot - 08-12-2023, 08:47 AM - Forum: Deals or Specials - No Replies

(Free Game Key) Train Valley 2 - Free Epic Games Game

Train Valley 2

To grab the game for free:
- Go to the store page of Train Valley 2
- https://store.epicgames.com/p/train-valley-2-3606da
- Click on the GET Button
- Verify that the price is zero
- Click on the Place Order Button
- That's it, the game will be added to you Epic Games Account

?GrabFreeGames.com ?Twitter ?Steam Curator ?Facebook[fb.me]?Discord[discord.gg]
❤️Support us: HumbleBundle Partner[www.humblebundle.com] Fanatical Affiliate[www.fanatical.com]


https://steamcommunity.com/groups/GrabFr...8964109572

Print this item

  Bring joy to development with Quarkus, the cloud-native Java framework
Posted by: xSicKxBot - 08-11-2023, 02:03 PM - Forum: Java Language, JVM, and the JRE - No Replies

Bring joy to development with Quarkus, the cloud-native Java framework

Our first DevNation Live regional event was held in Bengaluru, India in July. This free technology event focused on open source innovations, with sessions presented by elite Red Hat technologists.

Quarkus is revolutionizing the way that we develop Java applications for the cloud-native era, and in this presentation, Edson Yanaga explains why it also sparks joy.

Watch this live coding session to get familiar with Quarkus and learn how your old and new favorite APIs will start in a matter of milliseconds and consume tiny amounts of memory. Hot reload capabilities for development will bring you instant joy.

Watch the complete presentation:

See the slides here.

Learn more


Join us at an upcoming developer event, and see our collection of past DevNation Live tech talks.

Share

The post Bring joy to development with Quarkus, the cloud-native Java framework appeared first on Red Hat Developer.



https://www.sickgaming.net/blog/2019/10/...framework/

Print this item

  [Oracle Blog] Announcing Graal Cloud Native
Posted by: xSicKxBot - 08-11-2023, 02:01 PM - Forum: Java Language, JVM, and the JRE - No Replies

[Oracle Blog] Announcing Graal Cloud Native

Build portable cloud native Java microservices that start instantly and use fewer resources to reduce compute costs.

Graal Cloud Native (GCN) is a curated set of open source Micronaut® framework modules designed from the ground up to be compiled ahead-of-time with GraalVM Native Image resulting in native executables ideal for microservices.


https://blogs.oracle.com/java/post/annou...native-gcn

Print this item

  (Indie Deal) F1 Manager 2023, World War Z: Aftermath & SotTR
Posted by: xSicKxBot - 08-11-2023, 01:58 PM - Forum: Deals or Specials - No Replies

(Indie Deal) F1 Manager 2023, World War Z: Aftermath & SotTR

[www.indiegala.com]
The intense world of Formula 1® comes alive for a new season in F1® Manager 2023. 23 races, six F1® Sprint events, new cars, new circuits including the Las Vegas Strip Circuit, new drivers, new challenges… Your legacy begins here.
https://www.youtube.com/watch?v=t_Nw337WY2Q&ab_channel=F1%C2%AEManager
Victoria Games Sale, up to 90% OFF
[www.indiegala.com]
World War Z: Aftermath
[www.indiegala.com]
World War Z: Aftermath is the ultimate co-op zombie shooter inspired by Paramount Pictures’ blockbuster film, and the next evolution of the original hit World War Z that has now captivated over 15 million players.
https://www.youtube.com/watch?v=E-HivJSJ_aU&ab_channel=FocusEntertainment
Ubisoft Sale, up 85% OFF
[www.indiegala.com]
Shadow of the Tomb Raider Definitive Edition
[www.indiegala.com]
In Shadow of the Tomb Raider Definitive Edition experience the final chapter of Lara’s origin as she is forged into the Tomb Raider she is destined to be.
https://www.youtube.com/watch?v=Ul64NbyrkcQ&ab_channel=TombRaider


https://steamcommunity.com/groups/indieg...5429461188

Print this item

  (Free Game Key) Beholder 2 - Free GOG Game
Posted by: xSicKxBot - 08-11-2023, 01:58 PM - Forum: Deals or Specials - No Replies

(Free Game Key) Beholder 2 - Free GOG Game

Beholder 2 - Free GOG Game

Login / Register
Visit the store page of Beholder 2
https://www.gog.com/game/beholder_2
Click Add to cart
Click Check out now
Verify that the price is 0
Click Pay for your order now
Thats it, the game will be added to your account

?GrabFreeGames.com ?Twitter ?Steam Curator ?Facebook[fb.me]?Discord[discord.gg]
❤️Support us: HumbleBundle Partner[www.humblebundle.com] Fanatical Affiliate[www.fanatical.com]


https://steamcommunity.com/groups/GrabFr...8917344131

Print this item

  PC - Full Void
Posted by: xSicKxBot - 08-11-2023, 01:57 PM - Forum: New Game Releases - No Replies

PC - Full Void



Set in a dystopian future, Full Void is a 2D Cinematic Puzzle Platformer telling the story of a young teenager alone in a hostile world controlled by a rogue AI. Fight your way through puzzles and obstacles to uncover the story that surrounds this broken, run down society, where only children are still free. But for how long?

A pure hand drawn pixel art adventure that will keep you on your toes from the very beginning but still suitable for the whole family.

Full Void is a spiritual successor to classic cinematic puzzle platformers such as Prince of Persia, Another World (Out of This World) and Flashback, with a modern twist, innovative visual and gameplay mechanics.

Publisher: OutOfTheBit Ltd

Release Date: Jul 18, 2023




https://www.metacritic.com/game/pc/full-void

Print this item

  What’s new in Red Hat Dependency Analytics
Posted by: xSicKxBot - 08-10-2023, 09:25 PM - Forum: Java Language, JVM, and the JRE - No Replies

What’s new in Red Hat Dependency Analytics

We are excited to announce a new release of Red Hat Dependency Analytics, a solution that enables developers to create better applications by evaluating and adding high-quality open source components, directly from their IDE.

Red Hat Dependency Analytics helps your development team avoid security and licensing issues when building your applications. It plugs into the developer’s IDE, automatically analyzes your software composition, and provides recommendations to address security holes and licensing problems that your team may be missing.

Without further ado, let’s jump into the new capabilities offered in this release. This release includes a new version of the IDE plugin and the server-side analysis service hosted by Red Hat.

Support for Python applications


Along with Java (maven) and JavaScript (npm), Dependency Analytics now offers its full set of capabilities for Python (PyPI) applications. From your IDE, you can perform the vulnerability and license analysis of the “requirements.txt” file of your Python application, incorporate the recommended fixes, and generate the stack analysis report for more details.

Software composition analysis based on current vulnerability data


An estimated 15,000 open source packages get updated every day. On average, three new vulnerabilities get posted every day across JavaScript (npm) and Python (PyPi) packages. With this new release, the server-side analysis service hosted by Red Hat automatically processes the daily updates to open source packages that it is tracking. The hosted service also automatically ingests new vulnerability data posted to National Vulnerability Database (NVD) for JavaScript and Python packages. This allows the IDE plugin and API calls to provide source code analysis based on current vulnerability and release data.

Analyze transitive dependencies


In addition to the direct dependencies included in your application, Dependency Analytics now leverages the package managers to discover and add the dependencies of those dependencies, called “transitive” dependencies, to the dependency graph of your application. Analysis of your application is performed across the whole graph model and recommendations for fixes are provided across the entire set of dependencies.

Recommendations about complementary open source libraries


With this release, Dependency Analytics looks to recommend high-quality open source libraries that are complementary to the dependencies included in your application. The machine learning technology of the hosted service collects and analyzes various statistics on GitHub to curate a list of high-quality open source libraries that can be added to the current set of dependencies to augment your application. You can provide your feedback about the add-on libraries by clicking on the “thumbs-up” or “thumbs-down” icons shown for each recommendation. Your feedback is automatically processed to improve the quality of the recommendations.

IDE plugin support


The Dependency Analytics IDE plugin is now available for VS Code, Eclipse Che, and any JetBrains IDE, including IntelliJ and PyCharm.

We will continuously release new updates to our Dependency Analytics solution so you can minimize the delays in delivery of your applications due to last-minute security and licensing related issues.

Stay tuned for further updates; we look forward to your feedback about Dependency Analytics.

Share

The post What’s new in Red Hat Dependency Analytics appeared first on Red Hat Developer.



https://www.sickgaming.net/blog/2019/10/...analytics/

Print this item

  [Oracle Blog] Introducing the GraalVM Free License
Posted by: xSicKxBot - 08-10-2023, 09:24 PM - Forum: Java Language, JVM, and the JRE - No Replies

[Oracle Blog] Introducing the GraalVM Free License

Oracle GraalVM for JDK 17 and Oracle GraalVM for JDK 20 released under new Graal Free Terms and Conditions license.


https://blogs.oracle.com/java/post/graalvm-free-license

Print this item