2

So I am trying to convert a file (VDF (Valve Data Format)) from VDF to JSON - VDF is a custom format used by Valve that is basically a Key Value list. There is more info about the format Here.

I want to convert it from that format to JSON so I can more easily work with it and extract values using Newtonsoft.Json.

As far as I can tell, this conversion has already been done in PHP and Javascript, but there is no existing C# Code, and I am not very clear on how to do what was done in those cases.

I have been trying to make this work for the last 2 hours and so far have yet to come close to a working example, so please, any help creating this would be appreciated.

user3468962
  • 57
  • 1
  • 8

2 Answers2

3

Have a look at this project

Serializer/Deserializer for the Valve KeyValues data format written in c#

Eminem
  • 7,206
  • 15
  • 53
  • 95
  • 1
    Another one with the less restrictive MIT license: https://github.com/shravan2x/Gameloop.Vdf (the one from the accepted answer is GPL3) – Benlitz May 06 '17 at 21:50
2

The Gameloop.Vdf package is a high performance deserializer for VDF, written in purely managed C#. It works very similar to Json.NET.

VdfConvert.Deserialize(File.ReadAllText("importantInfo.vdf"))

The Gameloop.Vdf.JsonConverter add-on allows you to convert VDF objects and arrays to JSON easily. The resulting objects are from the Json.NET package and can even be bound to static models like you would usually do for json.

VProperty volvo = VdfConvert.Deserialize(File.ReadAllText("importantInfo.vdf"));
SteamModel sm = volvo.ToJson().ToObject<SteamModel>();

Disclaimer: I am the author of this package.

Hele
  • 1,558
  • 4
  • 23
  • 39