Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to load json file in SSIS by using script component but getting error as follow:-
Quote:
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)
at ScriptMain.CreateNewOutputRows()
at UserComponent.PrimeOutput(Int32 Outputs, Int32[] OutputIDs, PipelineBuffer[] Buffers, OutputNameMap OutputMap)
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.PrimeOutput(Int32 outputs, Int32[] outputIDs, PipelineBuffer[] buffers)
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StoreSales
{
    class jrpproject
    {
        public string SalesID { get; set; }
        public string OrderID { get; set; }
        public string CustomerID { get; set; }
        public string CustomerName { get; set; }
        public string PostalCode { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Region { get; set; }
        public string Latitude { get; set; }
        public string Longitude { get; set; }
        public string Country { get; set; }
        public string ProductCategory { get; set; }
        public string ProductSubCategory { get; set; }
        public string CustomerSegment { get; set; }
        public string ProductContainer { get; set; }
        public string ProductName { get; set; }
        public string ProductBaseMargin { get; set; }
        public string OrderPriority { get; set; }
    
        public string OrderDate { get; set; }
        public string ShipDate { get; set; }
        public string ShipMode { get; set; }
        public string ShippingCost { get; set; }
        public string QuantityOrdered { get; set; }
        public string UnitPrice { get; set; }
    
        public string Sales { get; set; }
        public string Discount { get; set; }
        public string Profit { get; set; }
    
    }
}
C#
#region Help: Introduction to the Script Component
/* The Script Component allows you to perform virtually any operation that can be accomplished in
* a .Net application within the context of an Integration Services data flow.
*
* Expand the other regions which have "Help" prefixes for examples of specific ways to use
* Integration Services features within this script component. */
#endregion

#region Namespaces

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using StoreSales;
using System.Collections.Generic;
using System.Text;
using System.Web.Script.Serialization;
using System.IO;
using System.Web.UI;
#endregion

///

/// This is the class to which to add your code. Do not change the name, attributes, or parent
/// of this class.
///
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    private string jsonfilecontent;
    private object row;
    #region Help: Using Integration Services variables and parameters
    /* To use a variable in this script, first ensure that the variable has been added to
    * either the list contained in the ReadOnlyVariables property or the list contained in
    * the ReadWriteVariables property of this script component, according to whether or not your
    * code needs to write into the variable. To do so, save this script, close this instance of
    * Visual Studio, and update the ReadOnlyVariables and ReadWriteVariables properties in the
    * Script Transformation Editor window.
    * To use a parameter in this script, follow the same steps. Parameters are always read-only.
    *
    * Example of reading from a variable or parameter:
    * DateTime startTime = Variables.MyStartTime;
    *
    * Example of writing to a variable:
    * Variables.myStringVariable = "new value";
    */
    #endregion
    #region Help:  Using Integration Services Connnection Managers
    /* Some types of connection managers can be used in this script component.  See the help topic
     * "Working with Connection Managers Programatically" for details.
     *
     * To use a connection manager in this script, first ensure that the connection manager has
     * been added to either the list of connection managers on the Connection Managers page of the
     * script component editor.  To add the connection manager, save this script, close this instance of
     * Visual Studio, and add the Connection Manager to the list.
     *
     * If the component needs to hold a connection open while processing rows, override the
     * AcquireConnections and ReleaseConnections methods.
     * 
     * Example of using an ADO.Net connection manager to acquire a SqlConnection:
     *  object rawConnection = Connections.SalesDB.AcquireConnection(transaction);
     *  SqlConnection salesDBConn = (SqlConnection)rawConnection;
     *
     * Example of using a File connection manager to acquire a file path:
     *  object rawConnection = Connections.Prices_zip.AcquireConnection(transaction);
     *  string filePath = (string)rawConnection;
     *
     * Example of releasing a connection manager:
     *  Connections.SalesDB.ReleaseConnection(rawConnection);
     */
    #endregion
    
    #region Help:  Firing Integration Services Events
    /* This script component can fire events.
     *
     * Example of firing an error event:
     *  ComponentMetaData.FireError(10, "Process Values", "Bad value", "", 0, out cancel);
     *
     * Example of firing an information event:
     *  ComponentMetaData.FireInformation(10, "Process Values", "Processing has started", "", 0, fireAgain);
     *
     * Example of firing a warning event:
     *  ComponentMetaData.FireWarning(10, "Process Values", "No rows were received", "", 0);
     */
    #endregion
    
    /// <summary>
    /// This method is called once, before rows begin to be processed in the data flow.
    ///
    /// You can remove this method if you don't need to do anything here.
    /// </summary>
    public override void PreExecute()
    {
        base.PreExecute();
        /*
         * Add your code here
         */
    }
    
    /// <summary>
    /// This method is called after all the rows have passed through this component.
    ///
    /// You can delete this method if you don't need to do anything here.
    /// </summary>
    public override void PostExecute()
    {
        base.PostExecute();
        /*
         * Add your code here
         */
    }
    
    public override void CreateNewOutputRows()
    {
        /*
          Add rows by calling the AddRow method on the member variable named "<output name="">Buffer".
          For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
        */
        String jsonFileContent = File.ReadAllText(@"D:\Data Analytics Class\Json FIle\200000.json");
    
        JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
    
        List<jrpproject> salesrows = js.Deserialize<list<jrpproject>>(jsonfilecontent);
        foreach (jrpproject row in salesrows)
        {
            Output0Buffer.AddRow();
            Output0Buffer.SalesID = row.SalesID;
            Output0Buffer.OrderID = row.OrderID;
            Output0Buffer.CustomerID = row.CustomerID;
            Output0Buffer.CustomerName = row.CustomerName;
            Output0Buffer.PostalCode = row.PostalCode;
            Output0Buffer.City = row.City;
            Output0Buffer.State = row.State;
            Output0Buffer.Region = row.Region;
            Output0Buffer.Latitude = row.Latitude;
            Output0Buffer.Longitude = row.Longitude;
            Output0Buffer.Country = row.Country;
            Output0Buffer.ProductCategory = row.ProductCategory;
            Output0Buffer.ProductSubCategory = row.ProductSubCategory;
            Output0Buffer.CustomerSegment = row.CustomerSegment;
            Output0Buffer.ProductContainer = row.ProductContainer;
            Output0Buffer.ProductName = row.ProductName;
            Output0Buffer.ProductBaseMargin = row.ProductBaseMargin;
            Output0Buffer.OrderPriority = row.OrderPriority;
            Output0Buffer.OrderDate = row.OrderDate;
            Output0Buffer.ShipDate = row.ShipDate;
            Output0Buffer.ShipMode = row.ShipMode;
            Output0Buffer.ShippingCost = row.ShippingCost;
            Output0Buffer.QuantityOrdered = row.QuantityOrdered;
            Output0Buffer.UnitPrice = row.UnitPrice;
            Output0Buffer.Sales = row.Sales;
            Output0Buffer.Discount = row.Discount;
            Output0Buffer.Profit = row.Profit;
        }
    }
}

Any solution please.....

What I have tried:

I have tried
1.different code than shown above
2.add more reference
3.follow google instructions
4.find out null in source file
Posted
Updated 12-Aug-20 22:07pm
v2
Comments
Richard MacCutchan 11-Aug-20 10:56am    
There is a key piece of information missing from your error message: the bit that tells you what the error is.

1 solution

Perhaps this would help you to achieve what you seek: Importing JSON Files Using SQL Server Integration Services[^]

It has detailed steps and states:
Quote:
SQL Server Integration Services does not support JSON natively, so we need to develop a custom source for a data flow task to load JSON file. In this tip, I will walkthrough a method to develop a bespoke source to load JSON files using .Net libraries.


Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900