I'm using json_field to store some json data for each content type which we then output as a json view. However when I output the view the data in the json field is escaped and works like a string instead of a subset of the json data.
eg
[
{
"nid": "175",
"title": "Joint Building house S & J K*****n",
"loan_package_file": "/drupal8/system/files/840/1491787660_840_docs.zip",
"loan_status": "serviced",
"created": "2017-04-10T12:34:24+1000",
"field_json_data": "{\"live_in_same_address\":true,\"same_assets\":\"\",\"same_liabilities\":\"\",\"property_address_same_home\":true,\"applicant_2_property_address_same_home\":\"\",\"is_joint_application\":\"Yes\",\"middle_name\":\"Alice\",\"last_name\":\"Kargaran\",\"title\":\"Mr\",\"gender\":\"Male\",\"first_name\":\"Samantha\",\"home_phone\":\"\",\"mobile_phone\":\"0412345678\",\"email\":\"test@gmail.com\",\"joint_app\":\"\",\"dependant\":\"2\",\"dependantssame\":\"\",\"marital_status\":\"Married\",\"date_of_birth\":\"10/10/1980\",\"dl_number\":\"\",\"dl_expiry_date\":\"\",\"dl_state\":\"\",\"building_a_new_home\":\"false\",\"purchasing_a_new_home\":\"false\",\"fhg\":\"false\",\"invest_home\":\"true\",\"refinance\":\"false\",\"refinance_and_payout_other_debts\":\"false\",\"loan_product_amount\":\"200000.00\",\"loan_length\":\"30\",\"defaults\":\"\",\"property_asset_unit_no\":\"\",\"property_asset_street_no\":\"100\",\"property_asset_street_name\":\"Ardvark St\",\"property_asset_street_type\":\"St\"}]}"
}]
Comments
Comment #2
sgp913 CreditAttribution: sgp913 commentedThis module is storing the JSON object as a serialized object (escaped string) in the database, not as a JSON object.
I think your view is printing out the string, so you need to unserialize it if you want to use it for something.
Maybe you can try hacking one of the views files to decode it.
This can help ↓
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Seri...
Another contrib module called JSONB stores the object in the DB directly as JSON, but it was not working for me (on MariaDB) so I ended up using this one.
Comment #3
DamienMcKennaYou are correct. I've committed a change (#2880415: Add support for JSON and JSONB database field types) that adds the raw JSON field types, but you'll unfortunately need to change the field type to use it.
Comment #4
DamienMcKennaThere's another issue that has moved further (#3207387: JSON string is escaped when access via REST) so I'm closing this one.