0

I am wanting to convert a Power BI File I have to a json file. The goal is to have a template that I can then take and programmatically modify (add tables/measures) and then upload the new file to client workspaces as needed. This would save us from having to manually edit each power bi file as we get a new client.

I know I can use TOM (Tabular Object Model) to edit power bi models via programs such as Visual Studio and Tabular Editor but was considering a json file may be easier to manipulate.

I attempted the below code in Visual Studios. I got an: does not contain a definition "toJson" error when I tried building this. Haven't found how to add ToJson yet. I am rather new to c# so this could be a simple ask.


namespace ConvertPowerBIFileToTMSL
{
    class Program
    {
        static void Main(string[] args)
        {
            string pbixFilePath = @"C:\Users\USER\Downloads\MyDashboard.pbix";
            string tmslFilePath = @"C:\Users\USER\Downloads\MyTMSLFile.json";

            using (var server = new Server())
            {
                server.Connect("localhost");

                var database = server.Databases.GetByName("MyDatabase");
                var model = database.Model;

                var tmsl = model.ToJson(pbixFilePath);
                File.WriteAllText(tmslFilePath, tmsl);
            }
        }
    }
}
  • Try json serializer : https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/how-to?pivots=dotnet-8-0 – jdweng Aug 17 '23 at 22:30

0 Answers0