February 6, 201412 yr hello to all. i want to use get url to get json data from a php file. when i run a script i get 3 rows in json. {"id":"2","userID":"1","app":"1","from_name":"danirub","from_email":"[email protected]","reply_to":"[email protected]","title":"test","plain_text":"","html_text":null,"sent":"1391675943","to_send":"5","to_send_lists":"3","recipients":"5","timeout_check":null,"opens":null,"wysiwyg":"0","send_date":null,"lists":null,"timezone":null,"errors":null,"bounce_setup":"0","complaint_setup":"0"},{"id":"3","userID":"1","app":"1","from_name":"danirub","from_email":"[email protected]","reply_to":"[email protected]","title":"bbbb","plain_text":"","html_text":" how can i split the result it to 2 or more records ? Thanks Dani
February 6, 201412 yr Create a global field g.allfields. Script: Set Variable[$jsonSplit; YourJsonField] # delete commas between braces Set Variable [$jsonSplit; Substitute($jsonSplit; "},{" ; "}{" )] # delete open braces Set Variable [$jsonSplit; Substitute ($jsonSplit; "{" ; "" )] # change close braces to pilcrow to make list Set Variable [$jsonSplit; Substitute[$jsonSplit; "}" ; "¶" )] # count number of records to be made Set Variable [$recordCount ; ValueCount($jsonSplit)] # create records Loop New Record/Request Set Field [ g.allfields; GetValue($jsonSplit; $recordCount)] Set Variable [$recordCount; $recordCount - 1] # # using the same technique of creating value lists # (this time converting the commas into pilcrows), # parse the name-value pairs in g.allfields # into field names and values. # Exit Loop If [ $recordCount = 0]
February 6, 201412 yr Create a global field g.allfields. ... Loop New Record/Request Set Field [ g.allfields; GetValue($jsonSplit; $recordCount)] Set Variable [$recordCount; $recordCount - 1] ... You are creating a new record and setting a global field to the record's group of values?
February 6, 201412 yr You're right, of course; it should NOT be global. I originally was thinking that I needed a global field to store the whole json, before I realized that it could be stored in a variable. Then I didn't delete the word "global" from the post.
February 6, 201412 yr Author Thanks very much. bus some there in not working right. can you have a lock @ the file please ? json.fmp12.zip
February 6, 201412 yr The JSON in field "a" has two object_name arrays, each of which contains 6 id arrays. Each id array has different name-value pairs. You did not indicate the object_name arrays in your original post. Exactly what do you wish to have in each record?
February 6, 201412 yr A couple more questions: 1. Does your real-world json always include two identical object_name arrays as your sample indicates? 2. Your sample data shows that userID and to_send are identical for each id. Is this the case in your real data?
February 9, 201412 yr Author Ageing thanks for the help. I suck with Substitute i am trying to insert data to fields but with no success. ho do i do it ? like to insert the data of "from_email" and "to_send"
Create an account or sign in to comment