"extracting JSON issue"

corkie
New Altair Community Member
hi guys,
I'd like to make an API call that requests a forecast for a particular location, receive the JSON code back and then convert it into an example set in rapidminer.
the code below is the API call, but I haven't had any luck developing the next part.
I'd appreciate any help.
I'd like to make an API call that requests a forecast for a particular location, receive the JSON code back and then convert it into an example set in rapidminer.
the code below is the API call, but I haven't had any luck developing the next part.
I'd appreciate any help.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="6.3.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="6.3.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="web:get_webpage" compatibility="5.3.002" expanded="true" height="60" name="Get Page (2)" width="90" x="45" y="120">
<parameter key="url" value="https://api.forecast.io/forecast/270255d4f537d8b330889abc76244d2f/52.27,-8.85?units=si"/>
<list key="query_parameters"/>
<list key="request_properties"/>
</operator>
<operator activated="true" class="web:json_to_xml" compatibility="5.3.002" expanded="true" height="60" name="Json to XML (2)" width="90" x="246" y="165"/>
<connect from_op="Get Page (2)" from_port="output" to_op="Json to XML (2)" to_port="document"/>
<connect from_op="Json to XML (2)" from_port="document" 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>
0
Answers
-
First thing you need to do is converting from the JSON doc to a dataset, next thing there are a few options but I would suggest to use the XPath extraction method since you have clean XML. Documentation is a bit poor but below example should get you started :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.015">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.3.015" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="web:get_webpage" compatibility="5.3.002" expanded="true" height="60" name="Get Page (2)" width="90" x="45" y="120">
<parameter key="url" value="https://api.forecast.io/forecast/270255d4f537d8b330889abc76244d2f/52.27,-8.85?units=si"/>
<list key="query_parameters"/>
<list key="request_properties"/>
</operator>
<operator activated="true" class="web:json_to_xml" compatibility="5.3.002" expanded="true" height="60" name="Json to XML (2)" width="90" x="179" y="120"/>
<operator activated="true" class="text:documents_to_data" compatibility="5.3.002" expanded="true" height="76" name="convertToData" width="90" x="313" y="120">
<parameter key="text_attribute" value="json"/>
</operator>
<operator activated="true" class="text:generate_extract" compatibility="5.3.002" expanded="true" height="60" name="Generate Extract" width="90" x="447" y="120">
<parameter key="source_attribute" value="json"/>
<parameter key="query_type" value="XPath"/>
<list key="string_machting_queries"/>
<list key="regular_expression_queries"/>
<list key="regular_region_queries"/>
<list key="xpath_queries">
<parameter key="timezone" value="//json/timezone/node()"/>
<parameter key="madis-station1" value="//json/flags/madis-stations[1]/node()"/>
<parameter key="madis-station2" value="//json/flags/madis-stations[2]/node()"/>
</list>
<list key="namespaces"/>
<parameter key="assume_html" value="false"/>
<list key="index_queries"/>
</operator>
<connect from_op="Get Page (2)" from_port="output" to_op="Json to XML (2)" to_port="document"/>
<connect from_op="Json to XML (2)" from_port="document" to_op="convertToData" to_port="documents 1"/>
<connect from_op="convertToData" from_port="example set" to_op="Generate Extract" to_port="Example Set"/>
<connect from_op="Generate Extract" 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>0