Parse Data on runtime into JSON

I have been trying to work out a subscription form for my game and thanks to you guys here, I came to a solution which works but still needs some changes.

The idea is to have an input field in the scene that takes the users email and convert it into JSON (to do a POST request). I have made the post request and everything works fine but I have to manually type the email in the inspector. What I would want is to get that value from the input field!

    public class testing : MonoBehaviour     {         public TMP_InputField myField;         //public InputField field;         [SerializeField]         private Email _email = new Email();         private string URL = "";          public void SaveData()         {             string data = JsonUtility.ToJson(_email); // this part here needs to be like _email.text             System.IO.File.WriteAllText(Application.persistentDataPath + "Data.json", data);             StartCoroutine(SaveIntoJson(URL , data));         }         IEnumerator SaveIntoJson(string url, string data)         {             var request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST);             request.SetRequestHeader("Content-Type", "application/json");             var jsonBytes = Encoding.UTF8.GetBytes(data);             request.uploadHandler = new UploadHandlerRaw(jsonBytes);             request.downloadHandler = new DownloadHandlerBuffer();                  yield return request.SendWebRequest();             if (request.isNetworkError || request.isHttpError)             {                 Debug.Log(request.error);                 Debug.Log(request.downloadHandler.text);             }             else             {                 Debug.Log("Form upload complete!");             }             Debug.Log(data);         }     }     [System.Serializable]     public class Email     {         public List<Profiles> profiles = new List<Profiles>();     }     [System.Serializable]     public class Profiles     {         [SerializeField]         public string email; // this part here works but i need to type the email in the inspector     } 

also the requirements for the json are like this

 {"profiles":[{"email":"testing@tes.com"}]} 

How can I separate it with Json decode and save it in PostgreSQL database with PHP?

I want to do web scraping with PHP. There is a json data in the URL, I want to pull this data and save it to the postgreSQL database. This is the code:

<?php  $  ch = curl_init(); $  url = "https://kurumsal.sokmarket.com.tr/ajax/servis/sehirler";  curl_setopt($  ch,CURLOPT_URL, $  url); curl_setopt($  ch,CURLOPT_RETURNTRANSFER, true);  $  resp = curl_exec($  ch);  if($  e = curl_error($  ch)) {     echo $  e; } else{     $  decoded = json_decode($  resp, true);     print_r($  decoded); }    //your database connection here  $  host = "localhost";  $  user = "postgres";  $  password = "****";  $  dbname = "sok";  // Create connection try{     $  this->linkid = @pg_connect("host=$  this->host port=5432 dbname=$  this->dbname user=$  this->user password=$  this->password");     if (! $  this->linkid)     throw new Exception("Could not connect to PostgreSQL server."); } catch (Exception $  e) {     die($  e->getMessage()); } foreach ($  array_data as $  row) { $  sql = "INSERT INTO il_adi (il) VALUES (decoded)"; $  conn->query($  sql); } $  conn->close();   ?> 

I can view the data I have captured in the array in the terminal. How can I save this to the database?

JSON Creation Issue

I’m new to PostgreSQL database. Although I’ve good experience on Oracle Database. I’m facing issue while generating JSON from Postgres. I’ve tried to generate the same output but not able to achieve is properly. Can someone please help or guide may be with examples on similar problem. I’ll be very much thankful to you.

"PostgreSQL 12.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit"

Tables and Sample Data.

CREATE TABLE PARKING_LOT (       PARKING_LOT_ID      NUMERIC(10)      ,PARKING_LOT_NAME    VARCHAR(100) ) ;  CREATE TABLE PARKING_LOT_VEHICLE_CLASS_MAP (       PARKING_LOT_ID       NUMERIC(10)      ,VEHICLE_CLASS_ID     NUMERIC(10)      ,AVAILABLE_SLOT_COUNT NUMERIC(10) ) ;   CREATE TABLE PARKING_SLOT (       PARKING_LOT_ID          NUMERIC(10)      ,VEHICLE_CLASS_ID        NUMERIC(10)      ,PARKING_SLOT_ID         NUMERIC(10)      ,SLOT_OCCUPANCY_STATUS   NUMERIC(10) ) ;   INSERT INTO PARKING_LOT VALUES( 1, 'PARKING 1' ) ; INSERT INTO PARKING_LOT VALUES( 2, 'PARKING 2' ) ;  INSERT INTO PARKING_LOT_VEHICLE_CLASS_MAP VALUES( 1, 1, 10 ) ; INSERT INTO PARKING_LOT_VEHICLE_CLASS_MAP VALUES( 1, 1, 11 ) ; INSERT INTO PARKING_LOT_VEHICLE_CLASS_MAP VALUES( 2, 2, 12 ) ; INSERT INTO PARKING_LOT_VEHICLE_CLASS_MAP VALUES( 2, 2, 13 ) ;  INSERT INTO PARKING_SLOT VALUES( 2, 1, 1, 1 ) ; INSERT INTO PARKING_SLOT VALUES( 2, 1, 2, 1 ) ; INSERT INTO PARKING_SLOT VALUES( 2, 2, 3, 0 ) ; 

Desired Output

{    "ResHeader":{       "ResDate":"09-01-2021 12:38:20",       "ResID":"12345",       "ResName":"Occupancy",       "ResDesc":"Parking Lot Availability and Occupancy Status"    },    "ResDetail":[       {          "ParkingLotID":"1",          "ParkingLotName":"PARKING 1",          "ParkingLotOccupancySummary":[             {                "VehicleClassID":"1",                "AvailableSlotCount":"10"             },             {                "VehicleClassID":"2",                "AvailableSlotCount":"12"             }          ]       },       {          "ParkingLotID":"2",          "ParkingLotName":"PARKING 2",          "ParkingLotOccupancySummary":[             {                "VehicleClassID":"1",                "AvailableSlotCount":"5",                "SlotOccupancyDetails":[                   {                      "SlotID":"1",                      "OccupancyStatus":"1"                   },                   {                      "SlotID":"2",                      "OccupancyStatus":"1"                   }                ]             },             {                "VehicleClassID":"2",                "AvailableSlotCount":"7",                "SlotOccupancyDetails":[                   {                      "SlotID":"3",                      "OccupancyStatus":"0"                   }                ]             }          ]       }    ] } 

What I’m able to achieve till now in bits and pieces

WITH     HEAD AS     (         SELECT json_build_object( 'ResHeader', H ) HeaderData         FROM         (             SELECT                  TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.MS') "ResDate"                 ,1  "ResID"         ) H     ) SELECT * FROM HEAD H  SELECT X.PARKING_LOT_ID, row_to_json(X) FROM (     SELECT VCM.PARKING_LOT_ID, VCM.VEHICLE_CLASS_ID  "VehicleClassID"     FROM PARKING_LOT_VEHICLE_CLASS_MAP2 VCM     LEFT OUTER JOIN PARKING_SLOT2 PS     ON VCM.PARKING_LOT_ID = PS.PARKING_LOT_ID ) X 

Regards Manoj

Generate JSON files for language translation from po file without wp-cli i18n make-json

My plugin uses wp_set_script_translations() to load translations for JS as mentioned here https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/.

I understand that when translations for a locale is added translate.wordpress.org it will create the JSON files.

But, we have a lot of site owners wants to translate a few words and start using the plugin. They can create .po and .mo files, but how they can create the JSON files without setting up wp-cli to use (wp i18n make-json).

Loco Translate plugin is not supporting JSON file generation.

I couldn’t find any online sites supporting .po to .json(with below mentioned format) conversion.

Out put file should in $ {domain}-$ {locale}-$ {handle}.json or $ {domain}-$ {locale}-$ {md5}.json JED 1.x ( .json ) file format for each JS file that called with wp_set_script_translations().

Alternative approaches to Iframes for content distribution via json api

I am currently working on a project that uses iframes to distribute content to customers. Going ahead we would like to switch to a json based rest api to deliver the content. Api access would need a token to which specific content could be exposed and traffic limits set.

To replace the frontend appearance of the iframe I am thinking about writing a reusable bundle using a lightweight react alternative like preactjs. But this would mean exposing the raw api and the specific token to the end user. Simply routing user requests via the customers server would conceal the token but still allow raw api access to the enduser.

What would be a good architecture for such a use case?

Are there server side rendered solutions that can easily be implemented across a variety of backend frameworks, without rewriting everything for each customer that is?

Thanks for any advice

Deserialize only some fields from a JSON file

I’m trying to parse a very large JSON string in Unity. I do not need all the fields and I can’t create a class with all the members.

It appears that all examples I have found, including the official docs, always deserialize and map every field to class members, which I cannot do for my application.

I tried creating a class that is similar to the JSON string, meaning that it has some members of the target JSON, just not all of them. But it’s not working as desired: all members of my class are always undefined after deserializing.

Here’s part of the string:

{     "Robots":[{"CanReset":false,     "CycleTime":123.875,     "Info":null,     "LevelInfo":null,     "Name":"FTF_10033",     "State":0,"     ...     }, ... } 

So I tried creating these classes:

[Serializable] public class jsonData {     public Robot[] robots; }  [Serializable] public class Robot {     public string Name = "Unknown AGV"; } 

And printing the results:

var jsonString = www.downloadHandler.text; jsonData jsonData_ = JsonUtility.FromJson<jsonData>(jsonString); Debug.Log("Json data: " + jsonData_); Debug.Log("Robots: " + jsonData_.robots); 

jsonData_ prints Json data: jsonData_, and jsonData_.robots prints nothing (just Robots:).

Is there any way to parse just these particular fields out of the JSON string?

I would be content with something like jsonString["robots"][0]["name"] or something.

Potential vulnerability in JSON response returning base 64 encoded image data, with the response being vulnerable to MIME sniffing

A JSON response in the API of a webapp is returning the base64 of a user-uploaded image, and there’s no X-Content-Type-Options Header to prevent MIME sniffing.

Could this be a potential vulnerability such as an XSS for the webapp by using steganography to edit the image with a payload, uploading it, and then MIME sniffing the JSON response? (or by any other means?)

Searching for substring in field that contains variable length of arrays of json objects

I am trying to construct a sql query, that searches for a substring within a field. The issue is that the field contains an array of one or more json objects.

For example the table looks like so:

day     |   items ____________________ Sunday  | [{"apples":5, "bananas":2}, {"pears":12, "cucumbers":9}, ...] Monday  | [{"apples":6, "bananas":1}, {"watermelon": 1}] Tuesday | [{"apples":4, "bananas":3}, {"tomatoes": 1}] 

How do I construct a SQL query that searches for a substring in items given it is not a string ?

Thanks

Is it necessary to encrypt a JSON Web Token more than what is built-in?

As a developer I do have some understanding of OWASP, I am also a member of OWASP community, official due paying one. Anyway, what I may not understand is information security in that I am not a security engineer and so I pose the following question:

Is it necessary to encrypt and encode a JSON Web Token?

In my experience, no secure or confidential information should be in a JSON Web Token anyway, outside of the id and email of the user. I can imagine a customer such as a bank freaking out about that, but what can someone do with an email? The password is salted and hashed and also at least in the NodeJS world that is my wheelhouse, JSON Web Token is tamper resistant.

I can verify that a token was valid by using the signing signature and if it fails due to tampering then the services will no longer trust it, that simple no? Why would it be necessary to encrypt it, Encode it And whatever else an overzealous engineer can think of? What problem is it solving or what use case is it handling that is not already built-in? Is it because in other programming languages there are no libraries built-in that can run a jwt.verify() on the JWT?

Could the case described in this post be what the institution is trying to solve?

JWT(Json Web Token) Tampering

I understand that for a customer for whom this is a big deal, encrypting the cookie contents is an option, but would that be overkill?

Can input value escape a JSON object?

I am passing value from input filled directly into a script function inside a JSON object. I was thinking, is it possible that this input can escape this object and can lead to XSS or something.

<script> ... function doSomething(item) { data = {'content':item} } ... </script>  <input id="search" type="text" value="" oninput="doSomething(this.value)"/>