Knowledge Management

Upload json array to KVStore

potluri_88
Explorer

Hi,

I'm trying to upload a json array with multiple objects to a kvstore using curl command as below.

curl -k -u admin:**** https://localhost:8089/servicesNS/nobody/test/storage/collections/data/hosts -H 'Content-Type: application/json' -d '[{"env": "dev", "zone": "Z1"},{"env": "dev", "zone": "Z1"}]'

Error is as below
JSON in the request is invalid. (
JSON parse error at offset 0 of file "[ {"env": "dev", "zone": "Z1"},{ "env": "dev", "zone": "Z1"}]": Expecting an object but got an array.

How do upload multiple object json without using an array?

0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@potluri_88

Have you tried batch_save ??

storage/collections/data/{collection}/batch_save

POST: Run one or more save (insert and replace) operations in a specific collection

Run multiple save operations:

Sample CURL Command:

curl -k -u admin:yourpassword \
    https://localhost:8089/servicesNS/nobody/kvstoretest/storage/collections/data/kvstorecoll/batch_save \
    -H 'Content-Type: application/json' \
    -d '[{"name": "Splunk Sweden"}, {"name": "Splunk Singapore"}]'

Check below link for more info:

http://dev.splunk.com/view/webframework-developapps/SP-CAAAEZG

Thanks

View solution in original post

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@potluri_88

Have you tried batch_save ??

storage/collections/data/{collection}/batch_save

POST: Run one or more save (insert and replace) operations in a specific collection

Run multiple save operations:

Sample CURL Command:

curl -k -u admin:yourpassword \
    https://localhost:8089/servicesNS/nobody/kvstoretest/storage/collections/data/kvstorecoll/batch_save \
    -H 'Content-Type: application/json' \
    -d '[{"name": "Splunk Sweden"}, {"name": "Splunk Singapore"}]'

Check below link for more info:

http://dev.splunk.com/view/webframework-developapps/SP-CAAAEZG

Thanks

0 Karma

potluri_88
Explorer

This really helped @kamlesh_vaghela .. thanks for your time..

Cheers!!

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Glad to help you @potluri_88

!!Happy Splunking!!

0 Karma

bjoernjensen
Contributor

Hi,

Since your collection expects a certain JSON object you have to use curl multiple times.

What should not work: using an object that contains your array that contains your objects.

Maybe that helps,
Björn

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...