json files

Does anyone have experience how to handle best json-format in Studio? Is there a appropriated filter somewhere out here? We got this format in a csv which we had to modify severely in order to get it in Studio. Thanks in advance for your hints!

Martha Ebermann

Parents Reply
  • Unknown said:
    Just to close that off... the problem was with the JSON file as it was incorrectly formed. Seemed to contain some leftover javascript on the first line of the file.

    In that case it maybe wasn't supposed to be a JSON file, but a JavaScript snippet containing an object variable definition (especially if it had a ".js" extension, not ".json").

    Many people confuse those two because the format looks very similar to JSON (of course, because JSON means "JavaScript Object Notation") and they don't have enough technical experience to see the difference.

    For example the following screenshot shows a JavaScript code snippet containing a call of "SC.stringsFor" function with two parameters: a language code and a JavaScript object consisting of a dictionary containing a few hundreds of key-value pairs.
    Although the file looks very similar to JSON, it is not JSON.

Children
  • Unknown said:
    In that case it maybe wasn't supposed to be a JSON file, but a JavaScript snippet containing an object variable definition (especially if it had a ".js" extension, not ".json").

    Nope, it was definitely JSON.  Just had this one line at the start that was incorrect:

    var translate = {

    All the rest of the file was JSON to the letter!

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

  • Unknown said:
    Nope, it was definitely JSON.  Just had this one line at the start that was incorrect:

    var translate = {

    Paul, but that's EXACTLY what I was talking about! That "extra" part is actually a JavaScript object variable definition.

    Unknown said:
    All the rest of the file was JSON to the letter!

    Of course it looks like JSON, because JSON syntax is simply taken from JavaScript object literal syntax!

  • I said it had javascript there that should not have been when you first decided to take me to task. Not sure why you decided to do this, but I guess you could be right. It's going to be one or the other. But in its current form it's neither. So I opted for the easier fix and for the easier one to handle for translation.

    For the file to be javascript it would have needed two things at least (many objects in the file and just making these changes alone still causes many errors in a javascript validator):

    1. closing syntax that was missing
    2. file extension that was not JSON

    For the file to be JSON it needed one thing:

    1. Remove the orphan javascript from the beginning

    The file looks to me as though it's been output for translation with a small error in how the files have been prepared.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

  • Unknown said:
    1. closing syntax that was missing
    2. file extension that was not JSON

    What "closing syntax" are you refering to exactly? A JavaScript object literal definition must be enclosed in curly braces just like a valid JSON. If the closing curly brace was there, it was all perfectly okay. If it wasn't there, it was invalid syntax for both formats.

    Unknown said:

    The file looks to me as though it's been output for translation with a small error in how the files have been prepared.

    That's exactly what I was pointing out - that people (usually due to lack of knowledge) confuse these two and create crippled files (e.g. JavaScript snippets with .json extension, etc.)... which are then further mistakenly understood by the poor recipients, who keep fixing the consequences instead of directing the sender to fix the CAUSE in the first place.