Jaahas.Json.TimeSeriesExtractor 1.0.0-preview4

This is a prerelease version of Jaahas.Json.TimeSeriesExtractor.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Jaahas.Json.TimeSeriesExtractor --version 1.0.0-preview4                
NuGet\Install-Package Jaahas.Json.TimeSeriesExtractor -Version 1.0.0-preview4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jaahas.Json.TimeSeriesExtractor" Version="1.0.0-preview4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jaahas.Json.TimeSeriesExtractor --version 1.0.0-preview4                
#r "nuget: Jaahas.Json.TimeSeriesExtractor, 1.0.0-preview4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Jaahas.Json.TimeSeriesExtractor as a Cake Addin
#addin nuget:?package=Jaahas.Json.TimeSeriesExtractor&version=1.0.0-preview4&prerelease

// Install Jaahas.Json.TimeSeriesExtractor as a Cake Tool
#tool nuget:?package=Jaahas.Json.TimeSeriesExtractor&version=1.0.0-preview4&prerelease                

About

Jaahas.Json.TimeSeriesExtractor is a library for extracting time series data from JSON documents using System.Text.Json. Its primary use case is separating structured JSON payloads from IoT and IIoT devices into separate time series for storage in a database or other time series data store.

More documentation is available on GitHub.

How to Use

Use the static TimeSeriesExtractor.GetSamples method to extract values from a JSON string or a JsonElement and return them as a collection of TimeSeriesSample objects:

const string json = @"{ ""timestamp"": ""2021-05-30T09:47:38Z"", ""temperature"": 24.7, ""pressure"": 1021.3, ""humidity"": 33.76 }";
var samples = TimeSeriesExtractor.GetSamples(json);

You can customise the extraction behaviour by providing a TimeSeriesExtractorOptions object when calling TimeSeriesExtractor.GetSamples:

// data.json
{
  "data": [
    {
      "src": "Instrument-1",
      "ts": "2024-04-13T10:01:47Z",
      "val": 1019
    },
    {
      "src": "Instrument-2",
      "ts": "2024-04-13T09:59:51Z",
      "val": 23.7
    },
    {
      "src": "Instrument-2",
      "ts": "2024-04-13T10:00:32Z",
      "val": 23.6
    }
  ]
}
var jsonOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
jsonOptions.Converters.Add(new JsonStringEnumConverter());

JsonElement json;
using (var stream = new FileStream("data.json", FileMode.Open)) {
    json = await JsonSerializer.DeserializeAsync<JsonElement>(stream, jsonOptions);
}

var options = new TimeSeriesExtractorOptions() {
    // We want to extract samples from nested objects.
    Recursive = true,
    // The "data" property in our JSON document contains an array of samples, each with its own 
    // timestamp.
    AllowNestedTimestamps = true,
    // The timestamp is located at the "ts" property on each sample object.
    TimestampProperty = "/ts",
    // Each object in the samples array contains a "val" property with the sample value. We'll use
    // an MQTT-style match expression to only extract values from the "val" property on each 
    // object in the samples array.
    CanProcessElement = TimeSeriesExtractor.CreateJsonPointerMatchDelegate(new JsonPointerMatchDelegateOptions() { 
        PointersToInclude = ["/data/+/val"],
        AllowWildcardExpressions = true
    }),
    // Each object in the samples array contains a "src" property with the name of the instrument
    // for the sample. We'll use this as the key when emitting a sample instead of inferring a key.
    Template = "{src}"
};

foreach (var sample in TimeSeriesExtractor.GetSamples(json, options)) {
    Console.WriteLine(JsonSerializer.Serialize(sample, jsonOptions));
}

// Output:
// {"key":"Instrument-1","timestamp":"2024-04-13T10:01:47Z","value":1019,"timestampSource":"Document"}
// {"key":"Instrument-2","timestamp":"2024-04-13T09:59:51Z","value":23.7,"timestampSource":"Document"}
// {"key":"Instrument-2","timestamp":"2024-04-13T10:00:32Z","value":23.6,"timestampSource":"Document"}

Please refer to the documentation for more information.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 98 10/11/2024
1.0.0-preview7 86 5/12/2024
1.0.0-preview5 122 4/16/2024
1.0.0-preview4 93 4/15/2024
1.0.0-preview3.0 70 4/13/2024
1.0.0-preview2.0 56 4/13/2024
1.0.0-preview1.0 60 4/12/2024
0.14.0 132 4/6/2024
0.13.0 114 4/5/2024
0.12.1 217 12/14/2023
0.12.0 123 12/14/2023
0.11.0 127 12/11/2023
0.10.0 190 6/12/2023
0.9.0 154 6/12/2023
0.8.0 431 8/19/2022
0.7.1 468 3/3/2022
0.7.0 438 3/3/2022
0.6.0 290 12/18/2021
0.5.0 279 12/16/2021
0.4.1 298 12/16/2021
0.4.0 282 12/16/2021
0.3.1 286 12/16/2021
0.2.0 322 6/1/2021
0.1.0 342 5/31/2021