Search for a value from in json

Hello,

I’m having a hard time with a simple trick, maybe you can help me.

Module 1 - Watch a row to get two numbers in 2 columns in this Google sheet.

Module 2 - Set multiple variables.

Item 1

Variable name : supplier

Variable value ; a json file which says that number x corresponds to such and such a supplier

Item 2

Variable name : category

Variable value; a json file which says that number x corresponds to such and such a category.

Module 3 - Set multiple variables.

Item 1

Variable name: suppliername

Variable value (and this is where I think it’s going wrong) : get ( ; variables[“supplier”] ; mapping of module 1 (Supplier ID column)

Item 2

Variable name : nomCategory

Variable value : get ( ; variables[“category”] ; mapping of module 1 (Category ID column)

Module 3 - Add a row

The feedback I have : variables[“supplier ‘] and variables[’category”]

I hope the translation is good, I’m french and I’m a beginner.

Thank you for your help.



To do this, you can try using the JSON “Parse JSON” module, or the Text parser “Match pattern” module —

Finds string elements matching a fixed pattern (regular expression).

For more information about the Parse JSON module and JSON app, see the corresponding Integrations page and the Help Centre documentation.

For more information about the Match pattern module and Text parser app, see the corresponding Integrations page and the Help Centre documentation.

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

@samliew

Thank you. It’s really too complicated for me, I just don’t get it!

If you need further assistance, please provide the following:

2. Scenario Blueprint

Please export the scenario blueprint. Providing your scenario blueprint file will allow others to quickly recreate and see how you have set up the mappings in each module, and also allows us take screenshots or provide module exports of any solutions we have for you in return - this would greatly benefit you in implementing our suggestions as you can simply paste module exports back into your scenario editor!

To export your scenario blueprint, click the three dots at the bottom of the editor then choose ‘Export Blueprint’.

You can upload the file here by clicking on this button:

3. Output Bundles of Modules

Please provide the output bundles of each of the relevant modules by running the scenario (you can also get this without re-running your scenario from the History tab).

Click on the white speech bubbles on the top-right of each module and select “Download input/output bundles”.

A. Upload as a Text File

Save each bundle contents in a plain text editor (without formatting) as a bundle.txt file.

You can upload the file here by clicking on this button:

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, especially if there are complex data structures (nested arrays and collections) or if external services are involved, and help you with mapping the raw property names from collections.

Sharing these details will make it easier for others to assist you.

Hey @Tim2 - 3 suggestions below:

1. Use switch() formula

  1. Remove your first “Set Multiple Variables” module.
  2. In your second “Set Multiple Variables” module, use the switch() formula like this:

switch({{1.`ID Fournisseur`}};3;Original Home;4;Chehoma;5;Casa Cubista;6;...)
switch({{1.`ID Catégorie`}};8;Art de la ...;9;Art de la ... > Accessorie;16;Art ... Linge de table;17;...)

Rough explanation of how the formula works: you’re “switching”/changing the output of the “variable” based on conditions - “IF_THIS” > “THEN_THAT”, or in your case “3” > “Original Home”, “4” > “Chehoma”, etc.

(See more examples in Make’s documentation)

  1. Your final scenario should then be:
    Google Sheets (trigger) > Set Multiple Variables (with switch() formulas) > Google Sheets (add a row)

(You can also just write the switch() formulas directly in Google Sheets [add a row] module and get rid of the “Set Multiple Variables” modules entirely)


2. Tools > Switch Module

If you don’t want to use the formula, there’s a dedicated module in Tools > Switch that does the same thing:

And you would set it up like this:

Both give you the same result, but if you use the Switch module you would need to add a second one for the category.

Final scenario: Google Sheets (trigger) > Switch module (for nomFournisseur) > Switch module (for nomCategorie) > Google Sheets (add a row)


3. Parse JSON

Alternatively, if you prefer to use the JSON you already have:

  1. Replace your first “Set Multiple Variables” module with a “Parse JSON” module. You can combine your two JSON collections into one like this:

  1. Right-click on the JSON module > “Run this module only” (this will parse the JSON and let you map the variables):

  1. And then, in your “Set Multiple Variables” module, you can map the correct value like this:

Final scenario: Google Sheets (trigger) > Parse JSON > Set Multiple Variables > Google Sheets (add a row)

(or put the get() formulas directly in the last Google Sheets module)


Cheers!

Super, great, fantastic!
Not only does it work, but I’ve got it all figured out - I could do it again!
It was superbly explained, and with kindness to boot.
The English support is not easy for a French person like me, even with the translation.
I tried the first and the third (which is the most practical, as I already had the json).
Thanks again, I loved learning this technique.

1 Like