diff --git a/index.js b/index.js index 04188e9..ef5c29a 100755 --- a/index.js +++ b/index.js @@ -61,7 +61,18 @@ dotnetProcess.stdout.on('end', () => { let json; try { - json = JSON.parse(stdout); + // Extract the JSON content between the markers + const startMarker = '<<<<<>>>>>'; + const endMarker = '<<<<<>>>>>'; + const startIndex = stdout.indexOf(startMarker); + const endIndex = stdout.indexOf(endMarker); + + if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) { + const jsonString = stdout.substring(startIndex + startMarker.length, endIndex).trim(); + json = JSON.parse(jsonString); + } else { + throw new Error('JSON markers not found or invalid order of markers.'); + } } catch (error) { return console.error([ 'The output from `csharp-models-to-json` contains invalid JSON.', diff --git a/lib/csharp-models-to-json/Program.cs b/lib/csharp-models-to-json/Program.cs index e77fa54..023a5c7 100644 --- a/lib/csharp-models-to-json/Program.cs +++ b/lib/csharp-models-to-json/Program.cs @@ -5,6 +5,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.Extensions.Configuration; using Ganss.IO; +using System.Text; namespace CSharpModelsToJson { @@ -36,7 +37,13 @@ static void Main(string[] args) } string json = JsonSerializer.Serialize(files); - System.Console.WriteLine(json); + + var sb = new StringBuilder(); + sb.AppendLine("<<<<<>>>>>"); + sb.AppendLine(json); + sb.AppendLine("<<<<<>>>>>"); + + System.Console.WriteLine(sb.ToString()); } static List getFileNames(List includes, List excludes) {