ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Special character in json object

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Special character in json object

    HI I've a problem with special character like & in a json, assuming I want to make a json with a field description that contains an & character, the db2 doesn't escaped automatically forbidden character automatically?

    I put an & into field description of table act.

    Code:
    Update Sample/Act
      Set Actdesc = 'MANAGE&ADVISE'
      Where Actkwd = 'MANAGE';
    then with this select I have a simple select:

    Code:
    Select json_object('key' : actkwd, 'description' : Actdesc) form
      From Sample/act
      where Actkwd = 'MANAGE';
    the result is:

    Code:
    {"key":"MANAGE","description":"MANAGE&ADVISE"}
    But this is not a valid json. Is there any special keyword to escape this character automatically?

    Many thanks!

  • #2
    To the best of my knowledge & is not a restricted character in JSON. A quick Google search does not show anything that says & is not allowed. Why do you think it's not allowed?

    Comment


    • #3
      correct, & is not a "forbidden" character, it is just a normal character in JSON -- no escaping is needed. Perhaps you are confusing JSON with XML?

      Comment


      • #4
        Hi all,

        I'm sorry, you are right.

        Many thanks.

        Comment

        Working...
        X