Unable to parse json data

sharmar6sharmar6 Member Posts: 19 Maven
edited December 2018 in Help

Hi, I am trying to fetch data from a API using "get_webpage". The website respods with a json array. No I am not able to use "cut document" to get specific values from the response by writing json queries.

 

I use the query  :  $.result.accountStatistics[0].summary.totalInteractionCount

 

 

 

<?xml version="1.0" encoding="UTF-8"?><process version="7.5.001">

  <context>

    <input/>

    <output/>

    <macros/>

  </context>

  <operator activated="true" class="process" compatibility="7.5.001" expanded="true" name="Process">

    <process expanded="true">

      <operator activated="true" class="web:get_webpage" compatibility="7.3.000" expanded="true" height="68" name="Twitter" width="90" x="45" y="34">


        <parameter key="accept_cookies" value="all"/>

        <list key="query_parameters"/>

        <list key="request_properties"/>

      </operator>

      <operator activated="true" class="text:cut_document" compatibility="7.5.000" expanded="true" height="68" name="Cut Document" width="90" x="246" y="34">

        <parameter key="query_type" value="JsonPath"/>

        <list key="string_machting_queries"/>

        <list key="regular_expression_queries"/>

        <list key="regular_region_queries"/>

        <list key="xpath_queries"/>

        <list key="namespaces"/>

        <list key="index_queries"/>

        <list key="jsonpath_queries">

          <parameter key="TotalIntercationCount" value="$.result.accountStatistics[0].summary.totalInteractionCount"/>

        </list>

        <process expanded="true">

          <connect from_port="segment" to_port="document 1"/>

          <portSpacing port="source_segment" spacing="0"/>

          <portSpacing port="sink_document 1" spacing="0"/>

          <portSpacing port="sink_document 2" spacing="0"/>

        </process>

      </operator>

      <connect from_op="Twitter" from_port="output" to_op="Cut Document" to_port="document"/>

      <connect from_op="Cut Document" from_port="documents" to_port="result 1"/>

      <portSpacing port="source_input 1" spacing="0"/>

      <portSpacing port="sink_result 1" spacing="0"/>

      <portSpacing port="sink_result 2" spacing="0"/>

    </process>

  </operator>

</process>

 

 

Json response :

 

{  
   "status":200,
   "result":{  
      "accountStatistics":[  
         {  
            "account":{  
               "id":1653853,
               "platform":"Twitter",
               "platformId":"331036671"
            },
            "summary":{  
               "totalInteractionCount":888,
               "postCount":6,
               "interactionRate":0.5536642849126482,
               "likeCount":625,
               "retweetCount":263
            },
            "breakdown":{  
               "native_video":{  
                  "totalInteractionCount":77,
                  "postCount":1,
                  "interactionRate":0.28825996,
                  "likeCount":45,
                  "retweetCount":32
               },
               "link":{  
                  "totalInteractionCount":195,
                  "postCount":3,
                  "interactionRate":0.24316337,
                  "likeCount":126,
                  "retweetCount":69
               },
               "tweet":{  
                  "totalInteractionCount":616,
                  "postCount":2,
                  "interactionRate":1.15303983,
                  "likeCount":454,
                  "retweetCount":162
               }
            },
            "subscriberData":{  
               "initialCount":26712,
               "finalCount":26750
            }
         },
         {  
            "account":{  
               "id":76760,
               "platform":"Twitter",
               "platformId":"136250134"
            },
            "summary":{  
               "totalInteractionCount":125,
               "postCount":3,
               "interactionRate":0.10868700792619887,
               "likeCount":91,
               "retweetCount":34
            },
            "breakdown":{  
               "photo":{  
                  "totalInteractionCount":75,
                  "postCount":2,
                  "interactionRate":0.09940621,
                  "likeCount":49,
                  "retweetCount":26
               },
               "tweet":{  
                  "totalInteractionCount":50,
                  "postCount":1,
                  "interactionRate":0.13254162,
                  "likeCount":42,
                  "retweetCount":8
               }
            },
            "subscriberData":{  
               "initialCount":37724,
               "finalCount":37722
            }
         },
         {  
            "account":{  
               "id":1545626,
               "platform":"Twitter",
               "platformId":"780606002"
            },
            "summary":{  
               "totalInteractionCount":15,
               "postCount":2,
               "interactionRate":0.10738666871212701,
               "likeCount":10,
               "retweetCount":5
            },
            "breakdown":{  
               "link":{  
                  "totalInteractionCount":15,
                  "postCount":2,
                  "interactionRate":0.11508363,
                  "likeCount":10,
                  "retweetCount":5
               }
            },
            "subscriberData":{  
               "initialCount":6517,
               "finalCount":6520
            }
         },
         {  
            "account":{  
               "id":2042715,
               "platform":"Twitter",
               "platformId":"201886840"
            },
            "summary":{  
               "totalInteractionCount":10,
               "postCount":1,
               "interactionRate":0.3308519437551696,
               "likeCount":8,
               "retweetCount":2
            },
            "breakdown":{  
               "photo":{  
                  "totalInteractionCount":10,
                  "postCount":1,
                  "interactionRate":0.33090668,
                  "likeCount":8,
                  "retweetCount":2
               }
            },
            "subscriberData":{  
               "initialCount":3022,
               "finalCount":3023
            }
         },
         {  
            "account":{  
               "id":2236790,
               "platform":"Twitter",
               "platformId":"847604654334554112"
            },
            "summary":{  

            },
            "breakdown":{  

            },
            "subscriberData":{  
               "initialCount":297,
               "finalCount":299
            }
         }
      ],
      "pagination":{  

      }
   }
}

 

Please help.
Tagged:

Answers

  • kaymankayman Member Posts: 662 Unicorn

    Seems it is expecting a double dot, this works :

     

    $.result.accountStatistics[0]..summary.totalInteractionCount

     

    As an alternative you can also just cut on the accountStatistics and then use a json to data component as below example, this makes it a bit more easy to work with the full set of data.

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.6.001">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="7.6.001" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="text:create_document" compatibility="7.5.000" expanded="true" height="68" name="Create Document" width="90" x="179" y="85">
    <parameter key="text" value="{&#10;&#9;&quot;status&quot;: 200,&#10;&#9;&quot;result&quot;: {&#10;&#9;&#9;&quot;accountStatistics&quot;: [&#10;&#9;&#9;&#9;{&#10;&#9;&#9;&#9;&#9;&quot;account&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;id&quot;: 1653853,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platform&quot;: &quot;Twitter&quot;,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platformId&quot;: &quot;331036671&quot;&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;summary&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 888,&#10;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 6,&#10;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.5536642849126482,&#10;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 625,&#10;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 263&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;breakdown&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;native_video&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 77,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 1,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.28825996,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 45,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 32&#10;&#9;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&#9;&quot;link&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 195,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 3,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.24316337,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 126,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 69&#10;&#9;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&#9;&quot;tweet&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 616,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 2,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 1.15303983,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 454,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 162&#10;&#9;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;subscriberData&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;initialCount&quot;: 26712,&#10;&#9;&#9;&#9;&#9;&#9;&quot;finalCount&quot;: 26750&#10;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;}, {&#10;&#9;&#9;&#9;&#9;&quot;account&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;id&quot;: 76760,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platform&quot;: &quot;Twitter&quot;,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platformId&quot;: &quot;136250134&quot;&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;summary&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 125,&#10;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 3,&#10;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.10868700792619887,&#10;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 91,&#10;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 34&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;breakdown&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;photo&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 75,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 2,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.09940621,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 49,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 26&#10;&#9;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&#9;&quot;tweet&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 50,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 1,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.13254162,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 42,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 8&#10;&#9;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;subscriberData&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;initialCount&quot;: 37724,&#10;&#9;&#9;&#9;&#9;&#9;&quot;finalCount&quot;: 37722&#10;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;}, {&#10;&#9;&#9;&#9;&#9;&quot;account&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;id&quot;: 1545626,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platform&quot;: &quot;Twitter&quot;,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platformId&quot;: &quot;780606002&quot;&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;summary&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 15,&#10;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 2,&#10;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.10738666871212701,&#10;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 10,&#10;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 5&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;breakdown&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;link&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 15,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 2,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.11508363,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 10,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 5&#10;&#9;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;subscriberData&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;initialCount&quot;: 6517,&#10;&#9;&#9;&#9;&#9;&#9;&quot;finalCount&quot;: 6520&#10;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;}, {&#10;&#9;&#9;&#9;&#9;&quot;account&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;id&quot;: 2042715,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platform&quot;: &quot;Twitter&quot;,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platformId&quot;: &quot;201886840&quot;&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;summary&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 10,&#10;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 1,&#10;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.3308519437551696,&#10;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 8,&#10;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 2&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;breakdown&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;photo&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;totalInteractionCount&quot;: 10,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;postCount&quot;: 1,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;interactionRate&quot;: 0.33090668,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;likeCount&quot;: 8,&#10;&#9;&#9;&#9;&#9;&#9;&#9;&quot;retweetCount&quot;: 2&#10;&#9;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;subscriberData&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;initialCount&quot;: 3022,&#10;&#9;&#9;&#9;&#9;&#9;&quot;finalCount&quot;: 3023&#10;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;}, {&#10;&#9;&#9;&#9;&#9;&quot;account&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;id&quot;: 2236790,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platform&quot;: &quot;Twitter&quot;,&#10;&#9;&#9;&#9;&#9;&#9;&quot;platformId&quot;: &quot;847604654334554112&quot;&#10;&#9;&#9;&#9;&#9;},&#10;&#9;&#9;&#9;&#9;&quot;summary&quot;: {},&#10;&#9;&#9;&#9;&#9;&quot;breakdown&quot;: {},&#10;&#9;&#9;&#9;&#9;&quot;subscriberData&quot;: {&#10;&#9;&#9;&#9;&#9;&#9;&quot;initialCount&quot;: 297,&#10;&#9;&#9;&#9;&#9;&#9;&quot;finalCount&quot;: 299&#10;&#9;&#9;&#9;&#9;}&#10;&#9;&#9;&#9;}&#10;&#9;&#9;],&#10;&#9;&#9;&quot;pagination&quot;: {}&#10;&#9;}&#10;}"/>
    </operator>
    <operator activated="true" class="text:cut_document" compatibility="7.5.000" expanded="true" height="68" name="Cut Document" width="90" x="313" y="85">
    <parameter key="query_type" value="JsonPath"/>
    <list key="string_machting_queries"/>
    <list key="regular_expression_queries"/>
    <list key="regular_region_queries"/>
    <list key="xpath_queries"/>
    <list key="namespaces"/>
    <list key="index_queries"/>
    <list key="jsonpath_queries">
    <parameter key="test" value="$.result.accountStatistics"/>
    </list>
    <process expanded="true">
    <connect from_port="segment" to_port="document 1"/>
    <portSpacing port="source_segment" spacing="0"/>
    <portSpacing port="sink_document 1" spacing="0"/>
    <portSpacing port="sink_document 2" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="text:json_to_data" compatibility="7.5.000" expanded="true" height="82" name="JSON To Data" width="90" x="447" y="85"/>
    <connect from_op="Create Document" from_port="output" to_op="Cut Document" to_port="document"/>
    <connect from_op="Cut Document" from_port="documents" to_op="JSON To Data" to_port="documents 1"/>
    <connect from_op="JSON To Data" from_port="example set" to_port="result 1"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="0"/>
    </process>
    </operator>
    </process>
Sign In or Register to comment.