uwe
uwe

Reputation: 4077

Coldfusion Json from structure

I'm using this code

<cfset user_data = StructNew() />
<cfset user_data[["field_a"]["und"]["tid"] = '123' /> 

<cfset json = SerializeJSON(user_data)>

It generates this json

{"und":{"tid":123}}

I would like to have the json look like this instead

{"und":[{"tid":123}]}

How do I have to change the struct?

Upvotes: 0

Views: 98

Answers (1)

Chris Tierney
Chris Tierney

Reputation: 1549

Use the following cfscript:

user_data = { 'und' = [ { 'tid' = '123' } ] };
json = serializeJSON(user_data);

you're not putting the key/value pair in an array as needed by your request.

Upvotes: 5

Related Questions