Import strings made by ENCODING JSON

I’m sorry if this is a primitive question, but appreciate if you advice how to import strings in data list. I want to export the data list by “ENCODING JSON”, edit them or add data, and import again. This is for the editing and back up purpose.

I looked through below but not sure how to do it.

Appreciate for your support.

Sho

Anyone can help me please? I can add more information if above is not enough. Appreciate for the support.

Hi there!

Can you explain a bit more about your situation, what do you mean by “export the data list by ENCODING JSON”?

Thank you so much Akseli,

What I meant was;

  1. I made array data list

  2. I made formula of ENCODING JSON for the data and got below (example). This is “export” I said.

[{“id”:“2020-11-09 21:51:33”,“Words”:“test1”,“Updateddate”:“2020-11-09 21:51:33”},{“id”:“2020-11-09 21:54:23”,“Words”:“test2”,“Updateddate”:“2020-11-09 21:54:23”},{“id”:“2020-11-14 16:22:40”,“Words”:“test3”,“Updateddate”:“2020-11-14 16:38:39”}]

  1. I want to change the data and/or add the new data in the list by editing the text. How can I import the changed text and update the data list (e.g. pasting the new text in the multi line input etc.)? Ideally want to keep the unchanged data, overwrite the changed data and newly registered the added data.

Hope this explains what I want to achieve. Appreciate for your support!

Sho

I concern my explanation was not good, but hope someone reply it or ask me questions to clarify it more. thank you for advices.

Hi! I would recommend doing the modifications to the data without encoding it to JSON, as doing any changes as JSON would require using REPLACE_ALL or REPLACE_ONE_REGEX or similar, and it would be very complex.

So let’s say from your example data that you have a data resource called “Test” which has the data you showed above like

Test {
  id,
  Words,
  Updateddate
}

You have set up this data as a data resource in Composer (see the docs for more help). Then you will simply add it as a data variable onto any page you want to use it on, and then you can modify it directly in any inputs. See the docs linked above for videos and guides on how to do this.

1 Like

Mevi, thank you so much and sorry for the delay in responding.

I already have such data variables like “Test”. From the data list, I want to 1) Export as a text array, 2) Edit the text outside of the app (e.g. Windows text editor) and 3) Import the text and Overwrite the original data list.

I assume the data has very long sentences and editing by PC works well. Using the data variable cannot achieve this.

Appreciate for your support.

Sho

Hi!

Hummmmm… Okay, I think this is possible, but just to let you know, this should not be how your users manage data in your app.

You can get the data out via ENCODE_JSON for example, if you go to developer tools on your browser you can copy the content of a text. Or you can set that on click of the text, you copy to clipboard the ENCODE_JSON of the data you want.

Then do the changes.

After, have a text-type page variable named e.g. dataToParse. Tie this to an input so that you can paste the changed data into it. (Make sure it’s valid JSON before pasting it back to the app)

Then in a JavaScript box, add the dataToParse as an input, e.g. the default input1, and use return JSON.parse(input.input1);. You should set the output result as List of Objects, preferably with the schema you want, or no schema at all.

Then you can with a formula (if you did not put the full schema to the output result) add this data back to the data variable.

Hi Mevi,
Thank you so much!
Sorry for the primitive question, but how can I import the data list made by the JavaScript box flow?
I want to know how to achieve “add this data back to the data variable” as your advice…

Sho

Ah. Just return the data list in the result of the javascript box.

Tutorial on this topic can be found here.

Mevi,

sorry for asking again and again…

I have looked through the tutorial and kept trying, but not works… Appreciate for your help again.

  1. Set the page variable “DatatoParse” of text (made by Encoding JSON) . And input it in javascript box. Out put is the list of list of text. It might have mistake?
    My Datatoparse is as below.
    [{“id”:“2020-11-09 21:51:33”,“Words”:“test1”,“Updateddate”:“2020-11-09 21:51:33”},{“id”:“2020-11-09 21:54:23”,“Words”:“test2”,“Updateddate”:“2020-11-09 21:54:23”},{“id”:“2020-11-14 16:22:40”,“Words”:“test3”,“Updateddate”:“2020-11-14 16:38:39”}]\

  1. Set page variable of “Importdata” from the output of javascript box. I want to find one data such as {“id”:“2020-11-09 21:51:33”,“Words”:“test1”,“Updateddate”:“2020-11-09 21:51:33”} from the list (page variable Importdata). Finding the data by the number of page varible “Loopindex”, which increases one by one loop. This is for identifying the one data for Create record.
    The Loopindex scheme is from https://forums.appgyver.com/t/reset-the-value-of-a-given-variable-to-0-for-all-records/973/2

Sorry and thank you again, but please advise?

Sho

Hi! Currently the output 1 is two nested lists inside of each other.

Also in the parse, you have input instead of inputs, and the return value needs to be in an Object.

return { JSON.parse(inputs.input1); }

Check first that you are getting the correct value from the javascript by alerting right after the javascript with ENCODE_JSON the result of the javascript (search under outputs for correct value).

Appreciate for you continuous advices. I’ll try it.
Can you reply to my question No.2?

I’m not sure I understand the second question, sorry, I’ll try. In any case, you first need to fix 1 for you to be able to do anything else.

After the javascript box, set into a page variable the result of the javascript box. The page variable can either be type List of Objects (with all properties of Object removed) or List of Objects (with all properties configured as they should be). Set the result of the javascript box with a formula if it does not set directly from the output, and then check the value of the page variable that it is correct (you can use the debugger or e.g. alert with ENCODE_JSON). Only proceed to looping once you have made sure the data is correct.

I don’t think you need the Each import data page variable, I would just directly in the Create record use PICK_ITEM to pick from the page variable the correct Object to create the record from.

Does this help?

Thank you again and again.

For question1, I have prepared as below but not works and kept struggling… Based on your advice, I set a debag flow of set page variable “test” by Encoding JSON of Javascript box output.
I’ll keep trying , but need to review the box. I input
return { JSON.parse(inputs.input1); }
and set list of objects.

I’m not sure if there are enough information, but appreciate if you find something wrong.


As you can see, in the javascript box there is a red underline under the text, which signifies an error. I did a quick test and it should be better when fixed to be

return { List: JSON.parse(inputs.input1) }

Where List is the name you have given to the output.

Can you get forward with this?

The “test” works now! thank you so much for your continuous support.

The app on my Android crashes every time after connecting with the following work flow, but I surely proceeded. I’ll keep trying sometimes. (e.g. change the loop flow)
For now I just want to show my gratitude for your supports.

Sho

1 Like

Glad you got it to work and happy to be of help! This is a heavy operation and should not be done every time, please save the end result somewhere instead and use that in your app, if you can.

Dear @Shozo_Setoguchi,

I’m also trying that work like you. So I want to ask for your help : How can you create a file to receive the data out ( export ). As I know, there is only “Create Directory” not “Create file” with AppGyver ?

@Mevi Could you please give instruction ?

Update : I figured out myself, thanks !

1 Like