Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate json with same name elements?
    text
    copied!<p>We offer an API for our website with both XML and JSON as returned formats. Both are coming from a PHP Array. My JSON return is what's causing me problems. How do I have same name elements returned instead of [0], <a href="https://developer.musixmatch.com/documentation/api-reference/artist-albums-get" rel="nofollow">1</a>, etc? Right now, my returned looks like:</p> <pre><code>{ "rate": { "rate_span": "1 Minute", "rate_limit": "60", "rate_remaining": 59, "rate_user": "60" }, "status": { "status_code": 200, "status_message": "Request was successful." }, "favorites": { "0": { "favorite": { "lyric_id": "570" } }, "1": { "favorite": { "lyric_id": "3530822107858532003" } }, "2": { "favorite": { "lyric_id": "3530822107858535795" } }, "favorites_type": "lyrics", "favorites_total": 3 } } </code></pre> <p>I'd rather each favorite be wrapped in it's own "favorite" { ... element and bypass each array being wrapped in [0], <a href="https://developer.musixmatch.com/documentation/api-reference/artist-albums-get" rel="nofollow">1</a>, [x+1].... Much like this JSON response: <a href="https://developer.musixmatch.com/documentation/api-reference/artist-albums-get" rel="nofollow">ARTIST.ALBUMS.GET JSON</a> </p> <p>This is the PHP array building the favorites part...</p> <pre><code>$json["favorites"] = array(); $json["favorites"]["favorites_type"] = "lyrics"; $json["favorites"]["favorites_total"] = $userFavorites-&gt;recordCount(); foreach($userFavorites as $key =&gt; $fav) { $song_id = $fav["lyric_id"]; $json["favorites"][]["favorite"]["lyric_id"] = $song_id; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload