<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Extracting Fields and Values from JSON Data in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345074#M63432</link>
    <description>&lt;P&gt;Your solution worked once I removed the input parameter as I am searching in my index. It does create the mappings correctly but it does not create fields from the fieldIds. &lt;/P&gt;

&lt;P&gt;I guess I was trying to replicate what the sourcetype should have done.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Aug 2017 05:54:28 GMT</pubDate>
    <dc:creator>ahallak2016</dc:creator>
    <dc:date>2017-08-04T05:54:28Z</dc:date>
    <item>
      <title>Extracting Fields and Values from JSON Data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345069#M63427</link>
      <description>&lt;P&gt;I have the following Dataset:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "createFormInstanceRequest": {
        "formId": "xxxxxxxxxxxxxxxxxxxxxxx",
        "requestOptions": {
            "requestAction": "SUBMIT"
        },
        "responseOptions": {
            "returnFormDefinition": false,
            "returnFormInfo": false,
            "returnFormData": true
        },
        "formData": {
            "groups": [{
                "groupId": "studentDetails",
                "iterations": [
                    [{
                        "fieldId": "studentName",
                        "value": ["timothy jones"]
                    }, {
                        "fieldId": "studentid",
                        "value": ["sxxxxxx"]
                    }, {
                        "fieldId": "address",
                        "value": ["12/12 some street"]
                    }, {
                        "fieldId": "attendingevent",
                        "value": ["No"]
                    }]
                ]
            }, {
                "groupId": "grades",
                "iterations": [
                    [{
                        "fieldId": "math",
                        "value": ["C"]
                    }, {
                        "fieldId": "PE",
                        "value": ["D"]
                    }, {
                        "fieldId": "english",
                        "value": ["A"]
                    }, {
                        "fieldId": "science",
                        "value": ["B"]
                    }]
                ]
            }]
        }
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am struggling to parse the field names and values as everything is placed in either: &lt;CODE&gt;createFormInstanceRequest.formData.groups{}.iterations{}{}.fieldId&lt;/CODE&gt; and &lt;CODE&gt;createFormInstanceRequest.formData.groups{}.iterations{}{}.value{}&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;They both become multivalue fields.&lt;/P&gt;

&lt;P&gt;I couldn't get SPATH to work with this data and changing the log format is not an option either.&lt;/P&gt;

&lt;P&gt;How can I create fields based on the fieldIDS and assign them the corresponding values in search time?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 04:47:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345069#M63427</guid>
      <dc:creator>ahallak2016</dc:creator>
      <dc:date>2017-08-02T04:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Fields and Values from JSON Data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345070#M63428</link>
      <description>&lt;P&gt;Ok, I have come up with a work around, its functional.. but it looks horrible:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myIndex sourcetype=json | rename "createFormInstanceRequest.formData.groups{}.iterations{}{}.value{}" as values,"createFormInstanceRequest.formData.groups{}.iterations{}{}.fieldId" as fields 
    | eval var0 = mvindex(fields,0) 
    | eval var1 = mvindex(fields,1) 
    | eval var2 = mvindex(fields,2) 
    | eval var3 = mvindex(fields,3) 
    | eval var4 = mvindex(fields,4) 
    | eval var5 = mvindex(fields,5) 
    | eval var6 = mvindex(fields,6) 
    | eval var7 = mvindex(fields,7)

    | eval {var0} = mvindex(values,0)
    | eval {var1} = mvindex(values,1)
    | eval {var2} = mvindex(values,2)
    | eval {var3} = mvindex(values,3)
    | eval {var4} = mvindex(values,4)
    | eval {var5} = mvindex(values,5)
    | eval {var6} = mvindex(values,6)
    | eval {var7} = mvindex(values,7)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With this, the values of fieldID will be the field names of the actual values relating to student.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 05:58:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345070#M63428</guid>
      <dc:creator>ahallak2016</dc:creator>
      <dc:date>2017-08-02T05:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Fields and Values from JSON Data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345071#M63429</link>
      <description>&lt;P&gt;Following is a run anywhere search to get single value mapping between fieldId and value instead of multivalue. I have used spath. However, you can use pipe commands from mvzip() onward.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval jsonData="
 {
     \"createFormInstanceRequest\": {
         \"formId\": \"xxxxxxxxxxxxxxxxxxxxxxx\",
         \"requestOptions\": {
             \"requestAction\": \"SUBMIT\"
         },
         \"responseOptions\": {
             \"returnFormDefinition\": false,
             \"returnFormInfo\": false,
             \"returnFormData\": true
         },
         \"formData\": {
             \"groups\": [{
                 \"groupId\": \"studentDetails\",
                 \"iterations\": [
                     [{
                         \"fieldId\": \"studentName\",
                         \"value\": [\"timothy jones\"]
                     }, {
                         \"fieldId\": \"studentid\",
                         \"value\": [\"sxxxxxx\"]
                     }, {
                         \"fieldId\": \"address\",
                         \"value\": [\"12/12 some street\"]
                     }, {
                         \"fieldId\": \"attendingevent\",
                         \"value\": [\"No\"]
                     }]
                 ]
             }, {
                 \"groupId\": \"grades\",
                 \"iterations\": [
                     [{
                         \"fieldId\": \"math\",
                         \"value\": [\"C\"]
                     }, {
                         \"fieldId\": \"PE\",
                         \"value\": [\"D\"]
                     }, {
                         \"fieldId\": \"english\",
                         \"value\": [\"A\"]
                     }, {
                         \"fieldId\": \"science\",
                         \"value\": [\"B\"]
                     }]
                 ]
             }]
         }
     }
 }
"
| spath input=jsonData path=createFormInstanceRequest.formId output=formId
| spath input=jsonData path=createFormInstanceRequest.formData.groups{}.iterations{}{}.fieldId output=fieldId
| spath input=jsonData path=createFormInstanceRequest.formData.groups{}.iterations{}{}.value{} output=value
| eval fieldValue=mvzip(fieldId,value)
| mvexpand fieldValue
| eval fieldValue=split(fieldValue,",")
| eval fieldId=mvindex(fieldValue,0)
| eval value=mvindex(fieldValue,1)
| table formId fieldId value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: I have retained formId if you want to perform further correlation with SPL.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 06:08:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345071#M63429</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-02T06:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Fields and Values from JSON Data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345072#M63430</link>
      <description>&lt;P&gt;@ahallak2016, will you always have 7 values?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 15:02:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345072#M63430</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-02T15:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Fields and Values from JSON Data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345073#M63431</link>
      <description>&lt;P&gt;At this point yes. I don't know if this will change in the future.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 05:51:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345073#M63431</guid>
      <dc:creator>ahallak2016</dc:creator>
      <dc:date>2017-08-04T05:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Fields and Values from JSON Data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345074#M63432</link>
      <description>&lt;P&gt;Your solution worked once I removed the input parameter as I am searching in my index. It does create the mappings correctly but it does not create fields from the fieldIds. &lt;/P&gt;

&lt;P&gt;I guess I was trying to replicate what the sourcetype should have done.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 05:54:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345074#M63432</guid>
      <dc:creator>ahallak2016</dc:creator>
      <dc:date>2017-08-04T05:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Fields and Values from JSON Data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345075#M63433</link>
      <description>&lt;P&gt;@ahallak2016, yes first part of my query until spath commands were to create mock data. You do not require them. &lt;/P&gt;

&lt;P&gt;I had messed up couple of field names as per your question. Possibly because of the same your query is not working as expected. Can you try with the following search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=myIndex sourcetype=json
| rename "createFormInstanceRequest.formData.groups{}.iterations{}{}.value{}" as values,"createFormInstanceRequest.formData.groups{}.iterations{}{}.fieldId" as fields, "createFormInstanceRequest.formId" as formId 
| eval fieldValue=mvzip(fields,values)
| mvexpand fieldValue
| eval fieldValue=split(fieldValue,",")
| eval fields=mvindex(fieldValue,0)
| eval values=mvindex(fieldValue,1)
| table formId fields values
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Aug 2017 06:08:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-Fields-and-Values-from-JSON-Data/m-p/345075#M63433</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-04T06:08:37Z</dc:date>
    </item>
  </channel>
</rss>

