You have two JSON feeds you want to merge and calc with the JSON-values.
Example-Solution:
Examle JSON-Feeds:
http://api.json-content-importer.com/extra/json/n1.json and
http://api.json-content-importer.com/extra/json/n2.json
Create a new JCI-Template and use one JSON-feed-URL as “URL of Template”
http://api.json-content-importer.com/extra/json/n1.json
twig:
{% set secondjsonurl = "http://api.json-content-importer.com/extra/json/n2.json" %} {% set sc = "[jsoncontentimporterpro url="~secondjsonurl ~" parser=twig3]{{_context | json_encode}}[/jsoncontentimporterpro]" %} {% set json2feed = (sc | doshortcode ) %} {% set json2feedk = (json2feed| json_decode ) %} no2 from the 1st JSON-feed: {{ no2 }}
this is the data from the 2nd JSON-feed: {{json2feedk | json_encode}}
now calc no1 * no2: {{ json2feedk.no1 * no2 }}
Explanation:
- “sc” is a string containing a JCI-shortcode for retrieving the 2nd JSON-URL. This Shortcode could also one with just [jsoncontentimporterpro id=...] for using another JCI-Template (in case the request is more complex).
- The “sc”-shortcode gives back {{_context | json_encode}}: This means the whole JSON is returned as pure string. Hence json2feed=(sc|doshortcode) executes the shortcode and sets json2feed as a JSON-string
- json2feedk=(json2feed|json_decode) converts the JSON-string to an JSON-array, which can be used just like the root-JSON-array of the 1st JSON-feed: json2feedk.no1 * no2
Importaint settings:
- The setting of “Usage of Shortcodes (JCI or other) in the JCI-twig-Template” (see JCI-Options, Tab “Shortcode-Settings”) must be on the default value. Otherwise the internal Shortcode might be executed at the wrong place
- At the same tab: “Nested JCI-Shortcodes: Use child-settings in parent-shortcode?” should be on ” Separate parent- and child-settings”, esp. when you use multiple jsoncontentimporterpro-shortcodes
In action:
no2 from the 1st JSON-feed: 5
this is the data from the 2nd JSON-feed: null
now calc no1 * no2: 0