Access JSON field dynamically

Hello
I have an HTTP call for the price of gold, here’s the response:

On a following module I want to be able to access the outputs dynamically, sometimes the 24k pricing, sometimes the 18k pricing, depending on a different variable I have.
How can I do that?
Can I write something like {{{{7.price_gram_{{variable}}}} where “variable” is “24k” for examlpe?

Welcome to the Make community!

You can use the built-in function if

e.g.:

if( condition; 1.varA; 1.varB )

For more information, see the if function documentation in the Help Center.

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

Getting Started

Help Centre Basics

Articles & Videos

Hope this helps! Let me know if there are any further questions or issues.

@samliew


P.S.: Did you know, the concepts of about 70% of questions asked on this forum are already covered in the Make Academy. Investing some effort into it will save you lots of time and frustration using Make later!

Thanks
But I want it to be dynamic and have the option to expand to more values that I currently don’t know about, so it should use a given variable and take the json value that has it as the key without using a limited number of IFs

Then it’s easier to do it without parsing the JSON first, and use a Text Parser module to get the dynamic variable value.

And how to use it then?

I’m not able to use a variable inside the regex pattern to grab the correct gold pricing though:

The X should be a variable taken from another module, which will be something like “Gold 24k”.

Not sure how to achieve that

Please provide an example output bundles of the HTTP modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.

A. Upload as Text File

Save each bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

B. Insert as Formatted Code Block

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles.
These are the two ways to format text so that it won’t be modified by the forum:

  • Method 1: Type code block manually

    Add three backticks ``` before and after the content/bundle, like this:

    ```
    content goes here
    ```

  • Method 2. Highlight and click the format button in the editor

Providing the input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

This will allow others to better assist you. Thanks!

Hope this helps! Let me know if there are any further questions or issues.

@samliew


P.S.: Did you know, the concepts of about 70% of questions asked on this forum are already covered in the Make Academy. Investing some effort into it will save you lots of time and frustration using Make later!