# Unable to ingest JSON data with PIPELINE INTO PROCEDURE

**URL:** <https://www.singlestore.com/forum/t/unable-to-ingest-json-data-with-pipeline-into-procedure/1702>\
**Category:** JSON\
**Tags:** studio\
**Created:** [March 13, 2020, 11:34am UTC](https://www.singlestore.com/forum/t/unable-to-ingest-json-data-with-pipeline-into-procedure/1702 "2020-03-13T11:34:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkodavoo](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pkodavoo](https://www.singlestore.com/forum/u/pkodavoo)\
**Post date:** [March 13, 2020, 11:34am UTC](https://www.singlestore.com/forum/t/unable-to-ingest-json-data-with-pipeline-into-procedure/1702/1 "2020-03-13T11:34:12Z")

</div>

Hi Team,

I am facing issue while ingesting a JSON data via PIPELINE to a table using Store Procedure.

I see NULL values are getting inserted in the table.

Procedure Script:

DELIMITER //  
CREATE OR REPLACE PROCEDURE ops.process\_users(GENERIC\_BATCH query(GENERIC\_JSON json)) AS  
BEGIN  
INSERT INTO ops.USER(USER\_ID,USERNAME)  
SELECT GENERIC\_JSON::USER\_ID, GENERIC\_JSON::USERNAME  
FROM GENERIC\_BATCH;  
END //  
DELIMITER ;

Pipeline Command

CREATE OR REPLACE PIPELINE ops.`tweet_pipeline_with_sp` AS LOAD DATA KAFKA ‘\<KAFKA\_SERVER\_IP\>:9092/user-topic’

INTO PROCEDURE ops.process\_users FORMAT JSON ;

Data Pushed to topic: {“USER\_ID”:“111”,“USERNAME”:“Test\_User”}

Table DDL: CREATE TABLE ops.USER (USER\_ID INTEGER, USERNAME VARCHAR(255));

Kindly help me out…

Thanks,  
Pradeep

---

<div class="post-metadata">

**Author:** ![sasha](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@sasha](https://www.singlestore.com/forum/u/sasha)\
**Post date:** [March 13, 2020, 11:29pm UTC](https://www.singlestore.com/forum/t/unable-to-ingest-json-data-with-pipeline-into-procedure/1702/2 "2020-03-13T23:29:59Z")

</div>

FORMAT JSON pipelines take a subvalue\_mapping clause which tells us how to map key paths in each input JSON to columns of the destination table or QTV. When it’s omitted, we’ll fall back to looking for keys matching the names of the destination’s columns. So in this case we attempted to find the key “GENERIC\_JSON” in the input object, and, because it was missing, assigned NULL.

For this particular example, you can and should (for performance reasons) omit the stored procedure:

> create or replace pipeline … into ops.USER(USER\_ID ← USER\_ID, USERNAME ← USERNAME) format JSON

If you really do need the stored procedure, the fix there is to explicitly tell us to assign the entire JSON to GENERIC\_JSON, with the special syntax `%`.

> create or replace pipeline … into ops.process\_users(GENERIC\_JSON ← %) format JSON

In case you haven’t seen it, the semantics of AS LOAD DATA … FORMAT JSON are defined here:

[https://docs.memsql.com/v7.0/reference/sql-reference/data-manipulation-language-dml/load-data/#json-load-data](https://docs.memsql.com/v7.0/reference/sql-reference/data-manipulation-language-dml/load-data/#json-load-data)

---

<div class="post-metadata">

**Author:** ![pkodavoo](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pkodavoo](https://www.singlestore.com/forum/u/pkodavoo)\
**Post date:** [March 16, 2020, 7:04am UTC](https://www.singlestore.com/forum/t/unable-to-ingest-json-data-with-pipeline-into-procedure/1702/3 "2020-03-16T07:04:19Z")

</div>

Hi Sasha,

I have tried with GENERIC\_JSON \<- % , It is actually working, But with some minor flaws!

Pipeline Script:

CREATE OR REPLACE PIPELINE ops.tweet\_pipeline\_with\_sp AS LOAD DATA KAFKA ‘172.17.0.3:9092/user-topic-1’  
INTO PROCEDURE ops.process\_users(GENERIC\_JSON \<- %) FORMAT JSON ;

JSON :

{“USER\_ID”: 111, “USERNAME”: “Test\_User”}

![image](https://forum-prod-assets20231213123829991800000001.s3.dualstack.us-east-1.amazonaws.com/original/1X/91af77c00a64db75abe0c8402bf57e592b385c88.png)

 ![image](https://forum-prod-assets20231213123829991800000001.s3.dualstack.us-east-1.amazonaws.com/original/1X/8db91be2c7afc26e05f3a1a9ec7b6e6f4ca7a275.png)

I see String value is getting inserted with double quotes on it. Whereas Integer works fine.

I have attached the screenshot for the same.

Can you please provide the documentation link referring to this behavior?

Thanks,  
Pradeep

---

<div class="post-metadata">

**Author:** ![sasha](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@sasha](https://www.singlestore.com/forum/u/sasha)\
**Post date:** [March 23, 2020, 4:39pm UTC](https://www.singlestore.com/forum/t/unable-to-ingest-json-data-with-pipeline-into-procedure/1702/4 "2020-03-23T16:39:19Z")

</div>

I believe the issue is that the `::` operator returns JSON subobjects _as JSON_, rather than as some automatically inferred SQL type. To extract a subobject and convert it to a SQL string, use `::$` or `json_extract_string()`, e.g.:

```
MemSQL [db]> create table t(a json);
MemSQL [db]> insert into t values('{"a":"hello"}');
MemSQL [db]> select a::a from t;
+---------+
| a::a |
+---------+
| "hello" |
+---------+
1 row in set (0.221 sec)

MemSQL [db]> select json_extract_string(a, 'a') from t;
+-----------------------------+
| json_extract_string(a, 'a') |
+-----------------------------+
| hello |
+-----------------------------+
1 row in set (0.186 sec)

MemSQL [db]> select a::$a from t;
+-------+
| a::$a |
+-------+
| hello |
+-------+
1 row in set (0.207 sec)

```

The JSON guide talks about this distinction ([SingleStoreDB Cloud · SingleStore Documentation](https://docs.memsql.com/v6.8/concepts/json-guide/#converting-a-json-string-value-into-a-sql-string)), though it should in fact likely have a louder warning.

---

<div class="post-metadata">

**Author:** ![pkodavoo](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pkodavoo](https://www.singlestore.com/forum/u/pkodavoo)\
**Post date:** [March 27, 2020, 10:08am UTC](https://www.singlestore.com/forum/t/unable-to-ingest-json-data-with-pipeline-into-procedure/1702/5 "2020-03-27T10:08:38Z")

</div>

Thank you Sasha. This solution worked!
