static void Main(string[] args) { string jsonString = ""; string s; while ((s = Console.ReadLine()) != null) { jsonString += s; } using var doc = JsonDocument.Parse(jsonString); var selectorString = args[0]; JsonSelector selector = null; try { selector = JsonSelector.Parse(selectorString); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(2); } try { IList <JsonElement> results = selector.Select(doc.RootElement); Console.WriteLine($"{JsonSerializer.Serialize(results)}"); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(1); } }
public static IList <JsonElement> Select(JsonElement root, string jsonPath, JsonSelectorOptions?options = null) { if (jsonPath == null) { throw new ArgumentNullException(nameof(jsonPath)); } var expr = JsonSelector.Parse(jsonPath); return(expr.Select(root, options)); }