Skip to content

Instantly share code, notes, and snippets.

@iFeelPixel
iFeelPixel / valve-data-format-jsonify.php
Created February 22, 2018 20:51 — forked from AlienHoboken/valve-data-format-jsonify.php
This short PHP script will create valid JSON data from Valve Data Format (VDF) data, such as items_game.txt files for TF2 and DotA 2. This allows for much greater ease in parsing the data it contains.
<?php
//load VDF data either from API call or fetching from file/url
//no matter your method, $json must contain the VDF data to be parsed
$json = file_get_contents("items_game.txt");
//encapsulate in braces
$json = "{\n$json\n}";
//replace open braces
$pattern = '/"([^"]*)"(\s*){/';