JsonSource Class

NReco.PivotData Class Library Documentation
Provides input data for PivotData from JSON stream.
Inheritance Hierarchy

SystemObject
  NReco.PivotData.InputJsonSource

Namespace:  NReco.PivotData.Input
Assembly:  NReco.PivotData.Extensions (in NReco.PivotData.Extensions.dll) Version: 1.6.1
Syntax

public class JsonSource : IPivotDataSource

The JsonSource type exposes the following members.

Constructors

  NameDescription
Public methodJsonSource
Initializes new JsonSource instance with specified TextReader.
Top
Properties

  NameDescription
Public propertyHeaders
Get or set explicit list of headers for JSON array values.
Public propertyRowsLimit
Get or set a limit for maximum number of CSV rows to read.
Top
Methods

  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Protected methodGetJsonReaderEnum
Public methodGetType (Inherited from Object.)
Protected methodGetValue
Protected methodMemberwiseClone (Inherited from Object.)
Public methodReadData
Reads data from CSV reader and provides it as IEnumerable with field access handler to the specified callback.
Public methodToString (Inherited from Object.)
Top
Remarks

JsonSource can read both array of objects (like '[ { ... }, { .... }]' or array of values (like '[ [...], [...] ]'). For array of values Headers should be specified.
Examples

Read data from array of values:
var inputJson = "[ [2015, true, 250 ], [2016, false, 100], [2016, true, 68] ]";
var jsonSource = new JsonSource( new StringReader(inputJson) ) { 
  Headers = new[] { "year", "active", "value" }
};
var pvtData = new PivotData(new[]{"year","active"}, new SumAggregatorFactory("value") );
pvtData.ProcessData(jsonSource);
Examples

Read data from array of objects:
var inputJson = "[ 
  {"year": 2015, "active": true, "value": 250 },
  {"year": 2016, "active": false, "value": 100 },
  {"year": 2016, "active": true, "value": 68}
]";
var jsonSource = new JsonSource( new StringReader(inputJson) );
var pvtData = new PivotData(new[]{"year","active"}, new SumAggregatorFactory("value") );
pvtData.ProcessData(jsonSource);
See Also

Reference